Extract PDF Watermark Details in Python

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

Read watermark text and bounds

Print the text and bounding rectangle of each pagination artifact with the WATERMARK subtype.

import aspose.pdf as ap

def extract_watermark_from_pdf(infile):
    with ap.Document(infile) as document:
        watermarks = [
            artifact
            for artifact in document.pages[1].artifacts
            if artifact.type == ap.Artifact.ArtifactType.PAGINATION
            and artifact.subtype == ap.Artifact.ArtifactSubtype.WATERMARK
        ]

        for watermark in watermarks:
            print(f"{watermark.text} {watermark.rectangle}")