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

2024-09-27 04:22:45 发布

您现在位置:Python中文网/ 问答频道 /正文

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


Tags: 文件信息pdf尺寸页面pages方向has
1条回答
网友
1楼 · 发布于 2024-09-27 04:22:45

您可以使用/Rotate来获得页面的旋转

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

它将产生以度为单位的值。尽管它可能对某些文档有用,但您应该注意,页面旋转本身并不表示方向。正如注释中的@mkl所述

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

相关问题 更多 >

    热门问题