how to Merge PDF files

Portable Document Format (PDF) is a widely used file format and is now an open standard for electronic document exchange maintained by the International Organization for Standardization (ISO). Merging files into one PDF is as important as creating a new PDF. In this article, we are going to discuss few simple steps to merge PDF files within a PHP application.

REST API for PDF format

Aspose.PDF Cloud allows you to create, read, update, merge, split or convert PDFs files within the language of your choice including .NET, Java, PHP, Ruby, Rails, Python, jQuery, and many more. However, this post covers how to merge multiple PDF files into a single PDF file in PHP. So in order to merge the PDFs, we need to first upload the input PDFs to Aspose Cloud storage or any supported third-party storage. Then send a PUT request to the Aspose Cloud service to perform the conversion. The following sections describe the process in more detail.

Merge Multiple PDFs using PHP

This REST example uses the PHP CURL library to send HTTP requests and handle HTTP responses so you need to install CURL to use these examples. Once the input PDF files are uploaded, you can use the following URI to merge PDFs on Aspose Cloud or any supported third-party storage.

You can use a couple of optional parameters with the above-mentioned URI. All or specific parameters can be used according to your requirement.

  • storage – This parameter can be used to set storage name if you are using a third party storage.
  • folder – This parameter can be used to set the name/path of the folder where input files have been uploaded.

After building the URI, you need to go through the following steps:

  1. Set App SID and App Key and sign the URI.
    See section 1 of the following code and Sign URI method for more details.
  2. Build JSON to post in the request body.
    A list of input documents including their paths should be provided. See section 2 of the following code.
  3. Send a PUT request to Aspose Cloud service.
    See section 3 of the following code and processCommand method for more details.
  4. Download merged PDF file if required.
    See section 4 of the following code.
  • Below is the code to merge multiple PDF files.

Merge Multiple PDFs using PHP SDK

If you want to use our PHP SDK to merge multiple PDF files, you can download this SDK from Aspose Cloud SDK for PHP. In order to use PHP SDK, you need to perform the following steps:

  1. Set the base product URI, App SID, App Key and output location
  2. Upload the input PDF files
  3. Create an object of the Document class and call the mergeDocuments method passing an array of names (including paths) of the input PDF files
  4. Download the merged PDF file

Following is the complete code.


This post has explained the steps on how we can easily combine multiple PDF files into a single resultant document using Aspose.PDF Cloud SDK for PHP. Please note that the complete source code of SDK is available on GitHub so that you can modify it as per your requirements. In the event of any related query or you encounter any issue while using it, please feel free to contact us via our Free product support forum.

Related article

We also recommend you visit the following link to learn more about