Extract PDF Watermark Details in Java

Read the text and bounding rectangle of watermark artifacts on the first page of a PDF in Java.

Extract watermark artifacts from a PDF

Use this example when you need to inspect existing watermark artifacts and read their text or position.

  1. Open the source PDF Document.
  2. Iterate through the artifact collection of the target page.
  3. Filter watermark pagination artifacts and print their text and rectangles.
public static void extractWatermarkFromPdf(Path inputFile) {
    try (Document document = new Document(inputFile.toString())) {
        for (Artifact artifact : document.getPages().get_Item(1).getArtifacts()) {
            if (artifact.getType() == Artifact.ArtifactType.Pagination
                    && artifact.getSubtype() == Artifact.ArtifactSubtype.Watermark) {
                System.out.println(artifact.getText() + " " + artifact.getRectangle());
            }
        }
    }
}