How to Remove Watermark from PDF File in Java

This quick tutorial guides on how to remove watermark from PDF file in Java by sharing the configuration details and a step-by-step process to accomplish the task. It also contains a runnable sample code to delete watermark from PDF in Java where the complete process is demonstrated in a simple manner. You will also learn the process to access different types of artifacts present on a PDF page.

Steps to Remove Watermark from PDF in Java

  1. Set the environment to use Aspose.PDF for Java for deleting the watermark
  2. Load the target PDF file into the Document object having few watermarks in it
  3. Create a list to hold the references of the target Artifacts that are to be deleted
  4. Parse through all the pages and their respective artifacts collection to check watermarks
  5. Save all the watermark artifacts in the list
  6. Delete all the selected artifacts and save the resultant PDF file

These steps describe the process to remove watermark from PDF document in Java by sharing the resources required to write the application and then a step-by-step program flow along with the introduction to the important classes. In this process, we have to identify all the watermark artifacts of each page and then delete them at the end. Once all or selected pages are processed, the resultant PDF file is saved on the disk.

Code to Remove All Watermarks from PDF in Java

This code demonstrates the process to remove background watermark from PDF in Java. It uses the getArtifacts() of the Page class to access all the artifacts and then test them against the enumerator Artifact.ArtifactSubtype.Watermark for deletion. You may also fetch other types of artifacts like header, footer, and background for different operations.

This article has taught us to erase watermark from PDF in Java. If you are interested in learning the process to add a watermark, refer to the article on how to add watermark to PDF using Java.

 English