Remove PDF Watermarks in Python

Remove watermark artifacts from the first page of a PDF in Python.

Remove watermark artifacts

The example removes only artifacts with the PAGINATION type and the WATERMARK subtype from the first page. Visible watermarks stored as regular page text, images, or annotations remain in the PDF.

import aspose.pdf as ap

def delete_watermark_artifact(infile, outfile):
    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:
            document.pages[1].artifacts.delete(watermark)

        document.save(outfile)