简体   繁体   中英

Python PyMuPDF / Fitz rotates image from extractImage

I am pulling out embedded images from pdf pages using PyMuPDF / Fitz. This works great but some pdf files, but for certain ones the image is rotated 90 deg. I don't see any condition that could be used to correct this. Has anyone experienced this? Anyone have a solution?

I always appreciate the help!

for img in doc.getPageImageList(i):
    xref = img[0]
    pix = doc.extractImage(xref)
    self.imagefilename = ("p%s-%s." % (i, xref)) + pix["ext"]
    imgout = open(self.imagefilename, 'wb')
    imgout.write(pix["image"])
    imgout.close()

Message from the repo maintainer:

For the most recent PyMuPDF versions (v1.17.0 and up), I have decided to use the unrotated page for everything that can be inserted or modified. Also every information about object location on a page now pertains to the unrotated page. In addition there are complementary tools which allow transformations between the respective coordinate systems.

BTW: there is a PyMuPDF attribute Page.rotation which returns the page rotation. And you can set it via Page.setRotation(90) .

I found the answer to my own question here:

https://stackoverflow.com/a/39324037/8222757

Using PyPDF2:

pdf = PyPDF2.PdfFileReader(open('example.pdf', 'rb'))
orientation = pdf.getPage(pagenumber).get('/Rotate')

The possible results can be 0 , 90 , 180 , 270 or None

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM