Have fun with sci.dog

python获得pdf文档页数

使用python获得pdf文档的页数,相对来说就很简单。

使用PyPDF2库即可。

代码很简单

from PyPDF2 import PdfFileReader
def get_pagenum(fullfile):
reader = PdfFileReader(fullfile)
return reader.getNumPages()

使用前,只需要安装PyPDF2库即可

pip install PyPDF2

使用这个函数也需要try,进行异常处理,将自动识别失败的,返回一个异常值。

赞(0)
未经允许不得转载:SciDog » python获得pdf文档页数

评论 抢沙发