Split PDF Guide

How to integrate the Split PDF tool into your application using iLovePDF’s REST API.

New to the API? Start with Processing a PDF: every tool guide builds on its task flow.

Basic split

There are several ways to split a PDF, but the simplest one is to define the page ranges to split:

Basic split
// Create a new task
$myTaskSplit = $ilovepdf->newTask('split');
// Add files to task for upload
$file1 = $myTaskSplit->addFile('path/to/file1_name.pdf');
// Set your tool options
$myTaskSplit->setRanges('2-4,6-8');
// Execute the task
$myTaskSplit->execute();
// Download the package files
$myTaskSplit->download();
PHP library ilovepdf/ilovepdf-phpcomposer require ilovepdf/ilovepdf-php

The property ranges can define multiple page ranges to split your document. You’ll have as a result a packaged file to download with as many files as ranges you have set.


According to this code example, the final output will be a ZIP file with two PDF files. One will contain pages 2 to 4 and the other will contain pages 6 to 8.


Note that if you set a range greater than the maximum number of pages in your document, you will get as many pages as can be split from this document. However, if your range starts with a page number greater than the number of pages in your document, you will receive an error and the process will fail.

Advanced split

We have seen how to split a document by page ranges, but there are more ways to split. See the following:

Split by fixed ranges

Split by fixed ranges
// Choose your processing tool
$myTaskSplit = $ilovepdf->newTask('split');
// Set your tool options
$myTaskSplit->setFixedRange(2);
PHP library ilovepdf/ilovepdf-phpcomposer require ilovepdf/ilovepdf-php

fixed_range will split your PDF every n pages. If you set a bigger fixed range number than the number of pages in your document, you will receive an error.

Split by removing pages

Split by removing pages
// Choose your processing tool
$myTaskSplit = $ilovepdf->newTask('split');
// Set your tool options
$myTaskSplit->setRemovePages('2-4,6-8');
PHP library ilovepdf/ilovepdf-phpcomposer require ilovepdf/ilovepdf-php

remove_pages allows you to set ranges of pages to be removed from your document and the resulting file comes back as a single PDF without the specified pages.

If you set a range as big as the number of pages in your document, you will receive an error.

Merge after split

Merge after split
// Choose your processing tool
$myTaskSplit = $ilovepdf->newTask('split');
// Set your tool options
$myTaskSplit->setRanges('2-4,6-8');
$myTaskSplit->setMergeAfter(true);
PHP library ilovepdf/ilovepdf-phpcomposer require ilovepdf/ilovepdf-php

When you split a document by setting specific ranges you can merge all these ranges together in a single file with merge_after. As a result, you will get a single PDF file.