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>
<id>AsposeJavaAPI</id>
<name>Aspose Java AP</name>
<url>https://releases.aspose.com/java/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>version of aspose-pdf API</version>
</dependency>
Steps to add Footer to PDF using Java
You need Aspose.PDF for Java to try the code in your environment.
- Open a PDF document using Document object.
- Create a Stamp and define its properties.
- Add the Stamp to Page using AddStamp method.
- Save the PDF file.
Add Image in Footer of PDF File - Java
Document pdfDocument = new Document(DATA_DIR.resolve("ImageInFooter.pdf").toString());
ImageStamp imageStamp = new ImageStamp(DATA_DIR.resolve("aspose-logo.jpg").toString());
imageStamp.setBottomMargin(10);
imageStamp.setHorizontalAlignment(HorizontalAlignment.Center);
imageStamp.setVerticalAlignment(VerticalAlignment.Bottom);
// Add footer on all pages
for (Page page : pdfDocument.getPages()) {
page.addStamp(imageStamp);
}
pdfDocument.save(DATA_DIR.resolve("ImageInFooter_out.pdf").toString());
pdfDocument.close();