In this tutorial, we will show you how to Split PDF by Text in PHP using PDF.co Web API. Below is the image of the PDF input with three pages and the split PDF files output.
Step 1 – Source Code
First, let’s copy the HTML and the PHP source code here.
Let’s save the files inside a folder in the www directory.
Step 2 – Start Apache
Next, open the files in your favorite editor and start the Apache server.
Step 3 – Run Program
Now, let’s run the program.
- In your browser type in
localhost/folder_name/sample.htmland hit Enter.
- Then, add your PDF.co API Key. You can get it in your PDF.co dashboard here.
- Load the sample PDF file. You can get a copy of the sample PDF Invoice here.
- In the Split Search Text field, let’s leave the default string invoice number. Every time the engine encounters the word invoice number it will split the page from the rest of the document.
Step 4 – Output
The sample PDF Invoice has three pages. Each page contains the word invoice number. The PDF Splitter Web API generated three URLs for each page.
Step 5 – Demo
Here’s the PDF.co PDF Splitter Web API in action
In this tutorial, you learned how to split PDF by text in PHP using PDF.co Web API. You also learned how to run the program using an Apache Server.