- Get started
- Overview
- Getting started
- Processing a PDF
- Common functions
- Error handling
- Organize
-
Merge PDF
-
Split PDF
-
Smart Split PDF (AI)
-
Rotate PDF
-
Add page numbers
- Optimize
-
Compress PDF
-
Repair PDF
-
PDF to PDF/A
-
Validate PDF/A
- Convert
-
Office to PDF
-
HTML to PDF
-
Images to PDF
-
PDF to JPG
- Edit and secure
-
Edit PDF
-
Watermark PDF
-
Protect PDF
-
Unlock PDF
- AI and data
-
OCR PDF
-
Extract text
-
PDF to Markdown (AI)
-
AI Summarizer (AI)
-
Detect forms (AI)
- No matches.
Resources
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:
// 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();// Create a new task
var taskSplit = api.CreateTask<SplitTask>();
// Add files to task for upload
var file1 = taskSplit.AddFile("path/to/file/file1_name.pdf");
// Set your tool options and Execute the task
taskSplit.Process(new SplitParams(new SplitModeRanges("2-4,6-8")));
// Download the package files
taskSplit.DownloadFile();# Create a new task
my_task_split = ilovepdf.new_task :split
# Add files to task for upload
file1 = my_task_split.add_file 'path/to/file1_name.pdf'
# Set your tool options
my_task_split.ranges = '2-4,6-8'
# Execute the task
my_task_split.execute
# Download the package files
my_task_split.downloadconst task = ilovepdf.newTask('split') as SplitTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.pdf'));
})
.then(() => {
return task.process({ split_mode: 'ranges', ranges: '2-4,6-8' });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejsThe 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
// Choose your processing tool
$myTaskSplit = $ilovepdf->newTask('split');
// Set your tool options
$myTaskSplit->setFixedRange(2);// Choose your processing tool
var taskSplit = api.CreateTask<SplitTask>();
// Set your tool options
taskSplit.Process(new SplitParams(new SplitModeFixedRanges(2)));# Choose your processing tool
my_task_split = ilovepdf.new_task :split
# Set your tool options
my_task_split.fixed_range = 2const task = ilovepdf.newTask('split') as SplitTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.pdf'));
})
.then(() => {
return task.process({ split_mode: 'fixed_range', fixed_range: 2 });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejsfixed_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
// Choose your processing tool
$myTaskSplit = $ilovepdf->newTask('split');
// Set your tool options
$myTaskSplit->setRemovePages('2-4,6-8');// Choose your processing tool
var taskSplit = api.CreateTask<SplitTask>();
// Set your tool options
taskSplit.Process(new SplitParams(new SplitModeRemovePages("2-4,6-8")));# Choose your processing tool
my_task_split = ilovepdf.new_task :split
# Set your tool options
my_task_split.remove_pages = '2-4,6-8'const task = ilovepdf.newTask('split') as SplitTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.pdf'));
})
.then(() => {
return task.process({ split_mode: 'remove_pages', remove_pages: '2-4,6-8' });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejsremove_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.
Merge after split
// Choose your processing tool
$myTaskSplit = $ilovepdf->newTask('split');
// Set your tool options
$myTaskSplit->setRanges('2-4,6-8');
$myTaskSplit->setMergeAfter(true);// Choose your processing tool
var taskSplit = api.CreateTask<SplitTask>();
// Set your tool options
taskSplit.Process(new SplitParams(new SplitModeRanges("2-4,6-8"))
{
MergeAfter = true
});# Choose your processing tool
my_task_split = ilovepdf.new_task :split
# Set your tool options
my_task_split.ranges = '2-4,6-8'
my_task_split.merge_after = trueconst task = ilovepdf.newTask('split') as SplitTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.pdf'));
})
.then(() => {
return task.process({ split_mode: 'ranges', ranges: '2-4,6-8', merge_after: true });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejsWhen 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.