提取pdf文件的元数据(尺寸或方向)



给定一个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')

它将产生一个以度为单位的值。尽管它可能对某些文档有用,但您应该注意,页面旋转本身并不表示方向As由@mkl在评论中提供。

至于其他元数据,您可以提取许多内容。您可以查看所有这些方法的PyPDF2.pdf.DocumentInformation方法。

最新更新