#πŸ”’ PyPDF2 display page?

18 messages Β· Page 1 of 1 (latest)

surreal tiger
#

I'm using PyPDF2 to put a watermark on every page of another pdf.

I had this working with v2 of PyPDF2, but since the library has been updated to v3, I can't seem to get it to work. There aren't any error messages, and my output pdf is created, there just isn't any watermark. Is there anyway to check pages along the way? Meaning, I'd like to be able to display the source page, the watermark image (that will be overlayed) and the output page on each iteration.

I looked in the docs for things like show and display but didn't see anything for the PageObject class.

crystal frostBOT
#

@surreal tiger

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

vague silo
#

hi

#

pypdf2's api changes between versions can sometimes make it tricky to adapt existing code

#

to solve this problem you might to need to use some additional tools

#

or libraries as it pypdf2 doesn't have built-in functionality for displaying pages directly

surreal tiger
#

yeah, I've also tried using matplotlib.pyplot's imshow but that didn't work either

vague silo
#

since pypdf2 doesn't support direct visualization of pdf pages, you can use the 'pdf2image' library

surreal tiger
#

but yeah...still working through it. I'm sure I'll get it, just didn't know if I was missing something easy to make troubleshooting go faster (and feel a bit more productive)

umbral elk
# surreal tiger I'm using PyPDF2 to put a watermark on every page of another pdf. I had this wo...

I'm not super surprised there is no show or display. My guess is PyPDF2 likely focuses on just manipulating the pdf data. Building a library capable of rendering a pdf document is an entirely different exercise. My suggested approach for a show PageObject would be to try to create a blank workbook, save the page to it, save it to a temp file, and then run a system command to open it it in a pdf viewer... not to say they couldn't have made a method that does all that, but I'm not seeing anything like that either.

vague silo
surreal tiger
#

@umbral elk Ahh...that makes sense. I think I'm making progress, it would just be nice to see the parts (since I'm also translating, rotating and scaling the watermark to fit odd sized pages). So I'd love to be able to do a watermark.show() - or similar to see what it looks like, same for the base page. Just to make sure I'm not translating the watermark completely off the page! ha!

#

@vague silo I haven't yet. But that's good to know. I'll probably hold off for the moment since I just started making a little progress. Thank you for the suggestion!

#

Going to close this for now. Thanks for the help to both of ya! πŸ‘

#

!close

crystal frostBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.