PDF Merger via PHP

Merge documents. Use Aspose.PDF for PHP via Java to modify PDF files programmatically

How to Merge PDF files Using PHP via Java

In order to merge PDF file, we’ll use Aspose.PDF for PHP via Java API which is a feature-rich, powerful and easy-to-use document manipulation tool in php-java. Install Tomcat 9.0 version on any location, add Aspose.PDF.war, for more details check the GitHub page.

Merge PDF files via PHP


To try the code in your environment, you need Aspose.PDF for PHP via Java.

  1. Open first document.
  2. Open second document.
  3. Add pages of second document to the first.
  4. Save concatenated output file

PHP - example code to merge PDF files


    // Open document
    $document = new Document($inputFile);

    // Open first document
    $document1 = new Document($inputFile1);
    
    // Open second document
    $document2 = new Document($inputFile2);

    // Add pages of second document to the first
    $document1->getPages()->add($document2->getPages());

    // Save concatenated output file
    $document1->save($outputFile);
    $document1->close();
    $document2->close();