问题描述
给定一个pdf文件,有没有办法找到它的页面尺寸和方向(水平或垂直)等? PyPDF2 库提供了检查页数的功能,但如何提取其他信息?是否可以使用此链接查找有关该文件的信息。创建日期、页数、标题等?或者任何其他可能的事情。
from PyPDF2 import PdfFileWriter,PdfFileReader
input1 = PdfFileReader(open("document1.pdf","rb"))
# print how many pages input1 has:
print "document1.pdf has %d pages." % input1.getNumPages()
https://pythonhosted.org/PyPDF2/
解决方法
您可以使用 /Rotate
来获得页面的旋转。
pdf = PyPDF2.PdfFileReader(open('document1.pdf','rb'))
orientation = pdf.getPage(pagenumber).get('/Rotate')
它将产生一个以度为单位的值。虽然它可能对某些文档有用,但您应该注意,页面旋转本身并不表示方向。正如 @mkl 在评论中所提供的。
至于其他元数据,您可以提取很多内容。您可以查看所有这些方法的 PyPDF2.pdf.DocumentInformation
方法。