Extract PDF Watermark Details in Java
Contents
[
Hide
]
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.
- Open the source PDF Document.
- Iterate through the artifact collection of the target page.
- 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());
}
}
}
}