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.

  1. Source Code
  2. Start Apache
  3. Run Program
  4. Output
  5. Demo
Split PDF By Text Input And Output Files
Split PDF by Text Input and Output Files

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.

HTML And PHP Files

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.html and 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.

Click Proceed.

Run Program

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.

PDF Splitter Web API Output

Step 5 – Demo

Here’s the PDF.co PDF Splitter Web API in action

Split PDF Demo
Split PDF Demo

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.