Add Footer to PDF via Java

Add Footer to PDF File using Java.

Add Footers to PDF Document Using Java

In order to add footers into PDF file, we’ll use Aspose.PDF for Java API which is a feature-rich, powerful, and easy-to-use conversion API for the Java platform. You can download its latest version directly from Maven and install it within your Maven-based project by adding the following configurations to the pom.xml.

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java AP</name>
    <url>https://releases.aspose.com/java/repo/</url>
</repository>

Dependency

<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>version of aspose-pdf API</version>
</dependency>

Steps to add Footer to PDF via Java


You need Aspose.PDF for 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 - Java

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


    Document pdfDocument = new Document(_dataDir + "ImageInFooter.pdf");
    ImageStamp imageStamp = new ImageStamp(_dataDir + "aspose-logo.jpg");
    imageStamp.setBottomMargin(10);
    imageStamp.setHorizontalAlignment(HorizontalAlignment.Center);
    imageStamp.setVerticalAlignment(VerticalAlignment.Bottom);
    // Add footer on all pages
    for (Page page : pdfDocument.getPages()) {
        page.addStamp(imageStamp);
    }
    _dataDir = _dataDir + "ImageInFooter_out.pdf";
    pdfDocument.save(_dataDir);