Add Footer to PDF using PHP

Add Footer to PDF File using PHP via Java.

Add Footers to PDF Document Using PHP

In order to add footers into 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.

Steps to add Footer to PDF using PHP


You need Aspose.PDF for PHP via Java to try the code in your environment.

  1. Open a PDF document using Document object.
  2. Create a Stamp and define its properties.
  3. Add the Stamp to Page using AddStamp method.
  4. Save the PDF file.

Add Image in Footer of PDF File - PHP

This sample code shows how to add image in footer of PDF


    // Open document
    $document = new Document($inputFile);
    
    // Create footer
    $imageStamp = new ImageStamp($inputImage);
    $horizontalAlignment = new HorizontalAlignment();
    $verticalAlignment = new VerticalAlignment();

    // Set properties of the stamp
    $imageStamp->setBottomMargin(10);
    $imageStamp->setHorizontalAlignment($horizontalAlignment->Center);
    $imageStamp->setVerticalAlignment($verticalAlignment->Bottom);

    $pages = $document->getPages();

    // Add footer to 1st page
    $page = $pages->get_Item(1);
    $page->addStamp($imageStamp);

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