Skip to content

There is no way to save part of PDF to PNG with PyPDF2? #936

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

You must be logged in to vote

PyPDF2 can extract all images from a PDF.

PyPDF2 currently cannot render the page to an image.

Anyway, how can I crop part of PDF; page width and 100 pixels down from top in PyPDF2?

You can change the cropbox of a page: https://pypdf2.readthedocs.io/en/latest/user/cropping-and-transforming.html

cropbox = page.cropbox
page.cropbox = RectangleObject([cropbox.left, cropbox.bottom, cropbox.right - 100, cropbox.top - 100])

However, if I remember it correctly, the unit is not (necessarily) in pixels. I would need to look that up in the specs.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@gosforth
Comment options

@Butterfly
Comment options

@gosforth
Comment options

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