Merge PDF documents programmatically
ConvertAPI provides a PDF Merge tool available as a REST API service. We crafted a PHP wrapper library for simple and convenient integration into your project. It is accessible via composer, and the source code can be found on GitHub. Simply sign up for a free account, grab your API secret key, install our PHP library, and you are good to go!
Install the ConvertAPI library into the PHP project
If you are using Composer, execute the following command in your project root to install this library:
composer require convertapi/convertapi-php
If you do not wish to use the Composer, you must require ConvertApi autoloader:
Please note that if installing manually without Composer, the library requires the following dependencies in order to work properly:
Merge PDF files using PHP
Once you have the library installed, you can use this code example showing how to join multiple PDF files using PHP programming language:
<?php require __DIR__ . '/../lib/ConvertApi/autoload.php'; use \ConvertApi\ConvertApi; # Code snippet is using the ConvertAPI PHP Client: https://github.com/ConvertAPI/convertapi-php # Read more about PDF Merge API: https://www.convertapi.com/pdf-to-merge ConvertApi::setApiSecret('your-api-secret'); $result = ConvertApi::convert('merge', [ 'Files' => [ '/path/to/sample-1.pdf', '/path/to/sample-2.pdf', '/path/to/sample-3.pdf', ], ], 'pdf' ); $result->saveFiles('/path/to/result/dir');
That's all it takes to implement a PDF merge functionality into the PHP project. You can combine local PDF files together with the files hosted on a server accessible via the URL, or the files uploaded to our server accessible by FileId.