Skip to content

How to know if PDF can have watermark (under text) or just a stamp (on top)? #1197

Answered by MartinThoma
zyzlik asked this question in Q&A
Discussion options

You must be logged in to vote

The issue you encounter is that the watermark goes behind an image. You could check if the page contains any image.

Something like this:

def contains_image(page: PageObject) -> bool:
    page_resources = page["/Resources"]

    x_object = page_resources.get("/XObject", {})

    for obj in x_object:
        obj_ = x_object[obj]
        if obj_["/Subtype"] == "/Image":
            return True
    return False

You could enhance this with the image dimensions. Or you could look at metadata (the generator). If you see Epson / Canon or similar in there, there is a good chance that it's a scanner.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@zyzlik
Comment options

@zyzlik
Comment options

@MartinThoma
Comment options

@MartinThoma
Comment options

Answer selected by zyzlik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants