In order to add image stamp into PDF, we’ll use Aspose.PDF for Java API which is a feature-rich, powerful and easy to use conversion API for 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>
Add Image Stamp to PDF Document Java
You need Aspose.PDF for Java to try the code in your environment.
- Load the PDF with an instance of Document.
- Open a PDF document using Document object.
- Create a Image Stamp and define its properties.
- Add the Stamp to Page using AddStamp method
Add Image Stamp to PDF - Java
// Open document
Document pdfDocument = new Document(DATA_DIR.resolve("AddImageStamp.pdf").toString());
// Create image stamp
ImageStamp imageStamp = new ImageStamp(DATA_DIR.resolve("aspose-logo.png").toString());
imageStamp.setBackground(true);
imageStamp.setXIndent(100);
imageStamp.setYIndent(100);
imageStamp.setHeight(48);
imageStamp.setWidth(225);
imageStamp.setRotate(Rotation.on270);
imageStamp.setOpacity(0.5);
// Add stamp to particular page
pdfDocument.getPages().get_Item(1).addStamp(imageStamp);
// Save output document
pdfDocument.save(DATA_DIR.resolve("AddImageStamp_out.pdf").toString());
pdfDocument.close();