英文:
How can PyPDF2 read the correct size of a PDF page
问题
我尝试使用PyPDF2获取PDF的宽度和高度:
w, h = page.mediaBox.getWidth(), page.mediaBox.getHeight()
print(w, h) # 显示 595 842
然而,实际上PDF的尺寸是 842 X 595(11.7 X 8.27 英寸)。
英文:
I tried to get width and height of pdf with PyPDF2 with
w, h = page.mediaBox.getWidth(), page.mediaBox.getHeight()
print(w, h) # showing 595 842
答案1
得分: 1
A PDF page can have a "viewing rotation" which causes the PDF viewer to rotate the page before showing it.
The viewing rotation for this page is 90 degrees or 270 degrees. Use PyPDF2 to find out the rotation, and swap the width and height if the rotation is 90 or 270.
You can normalise the pages to remove the viewing rotations whilst leaving the PDF visually intact with:
cpdf in.pdf -upright -o out.pdf
英文:
A PDF page can have a "viewing rotation" which causes the PDF viewer to rotate the page before showing it.
The viewing rotation for this page is 90 degrees or 270 degrees. Use PyPDF2 to find out the rotation, and swap the width and height if the rotation is 90 or 270.
You can normalise the pages to remove the viewing rotations whilst leaving the PDF visually intact with:
cpdf in.pdf -upright -o out.pdf
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论