PPTX DOCX XLSX PDF ODP
Aspose.PDF  for Java
PDF

Adding Watermark via Java

How to add watermark to PDF using Java

Add Watermark with Java Library

Add Watermark to 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 API</name>
    <url>https://repository.aspose.com/repo/</url>
    </repository>
    

 

Dependency

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

 

Add Watermark using Java

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

  1. Load the PDF with an instance of Document.
  2. Create an instance of WatermarkArtifact.
  3. Set properties of WatermarkArtifact object.
  4. Add watermark using method Add of Aspose.Pdf.Page.Artifacts collection class.
  5. Save PDF file

System Requirements

Just make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with Java Runtime Environment for JSP/JSF Application and Desktop Applications.
  • Development environment like Eclipse or IntelliJ IDEA.
  • Aspose.PDF for Java library referenced in your project.
 

Add Watermark in PDF - Java.

    // Open document
    Document doc = new Document(_dataDir + "text.pdf");
    FormattedText formattedText = new FormattedText("Watermark", java.awt.Color.BLUE,FontStyle.Courier, EncodingType.Identity_h, true, 72.0F);
    WatermarkArtifact artifact = new WatermarkArtifact();
    artifact.setText(formattedText);
    artifact.setArtifactHorizontalAlignment (HorizontalAlignment.Center);
    artifact.setArtifactVerticalAlignment (VerticalAlignment.Center);
    artifact.setRotation (45);
    artifact.setOpacity (0.5);
    artifact.setBackground (true);
    doc.getPages().get_Item(1).getArtifacts().add(artifact);
    doc.save(_dataDir + "watermark.pdf");
 

About Aspose.PDF for Java API

Aspose.PDF API can be used for PDF document manipulation and parsing within applications. One can create, modify, compress, secure, print or save PDF to TXT, HTML, PCL, XFA, XML, XPS, EPUB, TEX, Images and more formats. Aspose.PDF is a standalone API and it does not depend on any software including Adobe Acrobat.

Watermark PDF via Online App