Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
more pdf questions
#1
Hi,
in my efforts to save server space, I have a "how to" problem.
Using Fitz (pyMuPdf), I can : open a pdf and find the page I need (page_nr)
file_handle = fitz.open(pdf_path)
page = file_handle[page_nr]
page_img = page.get_pixmap()
I can save this pixmap as png on disk. OK.
Then I open it with PIL (Image.open...) and show it on a Tkinter canvas.
Question:
Can I somehow skip the part where I save on disk and open it with PIL?
In other words: how do I get from "page.get_pixmap()", directly to an
image object which has width and height and can be placed on a Tkinter canvas.
The whole point being that I do not need this image on disk, it is already inside the pdf.
thx,
Paul

EDIT: I think it' easier than I thought:
img = Image.open(StringIO.StringIO(page_img))
<- no results
EDIT 2: to whom it may concern, you will find many suggestions to do this, tried many, in the end only one really worked:
pix = page.get_pixmap(matrix=mat)
data = pix.tobytes("ppm")
img = Image.open(io.BytesIO(data),mode='r',formats=None)
It would seem something has been altered in the pix.tobytes() area "pixmap-object-has-no-attribute-getimagedata"
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020