how to save a pdf page to png bytes with typing [pyright issue] #3849
-
this is how i'm currently saving a pdf page to png bytes:
it works, but there is zero typing, and pyright throws a fit with every step of the way. error: Cannot access attribute "get_pixmap" for class "Page" also for the Argument of type "list[Unknown]" cannot be assigned to parameter "size" of type "tuple[int, int]" in function "frombytes" |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Can you explain why you are doing this in such a needlessly complicated way? Two statements are enough! pix = page.get_pixmap()
pix.save("some.png") |
Beta Was this translation helpful? Give feedback.
-
I need the png in bytes to send to a vision model. I didn't want to save to disk, just to re-open it as bytes. I'm processing a lot of pages and didn't want to thrash the disk with lots of IO when I could just keep the data in memory. I'm still learning the nuances of this library so there's probably a better way to get the png version of each page in bytes, but so far I can't find a better way. Thanks for the help! |
Beta Was this translation helpful? Give feedback.
"Saving" to memory is just as simple:
Looking in help():