Add Pages to PDF using PHP

Insert pages to PDF document programmatically using Aspose.PDF for PHP via Java Library

How to Add pages to PDF using PHP

In order to add page in 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.

Insert Page to PDF using PHP


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

  1. Create a Document object with the input PDF file.

  2. Call the PageCollection collection’s Insert method with specified index.

  3. Save the output PDF using the Save method.

Insert New Page to PDF


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

    // Add page
    $document->getPages()->add();

    // Insert an empty page in a PDF
    $document->getPages()->insert(2);

    // Save output document
    $document->save($outputFile);
    $document->close();