Move Pages to PDF using PHP

Move Pages in PDF document. Use Aspose.PDF for PHP via Java to modify PDF files programmatically

How to Move pages to PDF using PHP

In order to move page from 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.

Move 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. Get Page from the the PageCollection collection’s.
  3. Save the output PDF using the Save method.
  4. Add page to the destination document. Save output file.
  5. Delete page in source document.
  6. Save the source PDF using the Save method.

Moving a Page from one PDF Document to Another


    // Open document
    $document = new Document($inputFile1);
    $dstDocument = new Document($outputFile);
    
    $page = $document->getPages()->get_Item(2);
    $dstDocument->getPages()->add($page);

    // Save output file
    $dstDocument->save($srcFileName);
    $document->getPages()->delete(2);
    $document->save($dstFileName);
    $document->close();
    $dstDocument->close();
  
    // Save output document
    $document->save($outputFile);
    $document->close();