Remove Watermark from PDF via Java

Delete watermark from PDF document using Aspose.PDF for Java Library

Delete Watermark from PDF File Using Java Library

Delete Watermark from 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>

Remove Watermark via 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

Delete Watermark from PDF - Java


    doc = new com.aspose.pdf.Document("1.pdf");

    if(doc.getPages().get_Item(1).getArtifacts().get_Item(1).getSubtype() == com.aspose.pdf.Artifact.ArtifactSubtype.Watermark)
        doc.getPages().get_Item(1).getArtifacts().delete(doc.getPages().get_Item(1).getArtifacts().get_Item(1));

    //save result pdf to file
    doc.save("remove_watermark.pdf", com.aspose.pdf.SaveFormat.Pdf);