How to know if PDF can have watermark (under text) or just a stamp (on top)? #1197
-
I have different PDF files: some are digitally generated and some are scans / images. I have to put watermark on them and preferable under the text. I used Is there a better way to determine if watermark can be behind text? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
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. |
Beta Was this translation helpful? Give feedback.
The issue you encounter is that the watermark goes behind an image. You could check if the page contains any image.
Something like this:
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.