我尝试在 Python 3 中使用 PyPDF2 模块,但无法显示“页面大小”属性。 我想知道扫描为 PDF 文件之前纸张尺寸是多少。
类似这样的:
import PyPDF2
pdf=PdfFileReader("sample.pdf","rb")
print(pdf.getNumPages())
但我正在寻找另一个 Python 函数,而不是 getNumPages()...
下面的命令打印某种元数据,但不显示页面大小:
pdf_info=pdf.getDocumentInfo()
print(pdf_info)
最佳答案
这段代码应该可以帮助你:
import PyPDF2
pdf = PyPDF2.PdfFileReader("a.pdf","rb")
p = pdf.getPage(1)
w_in_user_space_units = p.mediaBox.getWidth()
h_in_user_space_units = p.mediaBox.getHeight()
# 1 user space unit is 1/72 inch
# 1/72 inch ~ 0.352 millimeters
w = float(p.mediaBox.getWidth()) * 0.352
h = float(p.mediaBox.getHeight()) * 0.352
关于python - 如何使用Python获取PDF文件元数据 'Page Size'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46232984/