- PDF REST API Guides
- Welcome
- First steps
- Getting started
- Processing a PDF
- Common functions
- Topics
- Encrypt files
- Error handling
- Tool guides
- Merge PDF Guide
- Split PDF Guide
- Compress PDF Guide
- OCR PDF Guide
- Convert Office to PDF Guide
- Convert PDF to JPG Guide
- Convert Images to PDF Guide
- PDF to PDF/A Guide
- HTML to PDF Guide
- Validate PDF/A Guide
- Rotate PDF Guide
- Unlock PDF Guide
- Protect PDF Guide
- Watermark PDF Guide
- Add Page Numbers Guide
- Repair PDF Guide
- Extract Text Guide
- Edit PDF Guide
Merge PDF Guide
Develop your own solution to combine multiple PDF files by integrating with iLovePDF’s REST API.
Remember that in order to use our Tool Guides, you need to have previous knowledge about the basics to
processing a PDF with our REST API. We strongly recommend that you read the Processing a PDF guide
before starting this one.
Basic merge
Merge is one of the simplest iLoveAPI tools to use and can be done by simply uploading two or more files, as shown in this example code:
Examples using a library
// Create a new task
$myTaskMerge = $ilovepdf->newTask('merge');
// Add files to task for upload
$file1 = $myTaskMerge->addFile('path/to/file1_name.pdf');
$file2 = $myTaskMerge->addFile('path/to/file2_name.pdf');
// Execute the task
$myTaskMerge->execute();
// Download the package files
$myTaskMerge->download();
xxxxxxxxxx
// Create a new task
var taskMerge = api.CreateTask<MergeTask>();
// Add files to task for upload
var file1 = taskMerge.AddFile("file1.pdf");
var file2 = taskMerge.AddFile("file2.pdf");
// Execute the task
taskMerge.Process();
// Download the package files
taskMerge.DownloadFile();
xxxxxxxxxx
# Create a new task
my_task_merge = ilovepdf.new_task :merge
# Add files to task for upload
file1 = my_task_merge.add_file 'path/to/file1_name.pdf'
file2 = my_task_merge.add_file 'path/to/file2_name.pdf'
# Execute the task
my_task_merge.execute
# Download the package files
my_task_merge.download
x
const task = ilovepdf.newTask('merge') as MergeTask;
task.start()
.then(() => {
return task.addFile('path/to/file1_name.pdf');
})
.then(() => {
return task.addFile('path/to/file2_name.pdf');
})
.then(() => {
return task.process();
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});
In this example, file1_name.pdf and file2_name.pdf will be merged into a single PDF with a default filename.
Merge is that simple. Remember that you can explore more functions like setting the output filename in the Common functions guide.