from PyPDF2 import PdfFileWriter, PdfFileReader
output = PdfFileWriter()
input1 = PdfFileReader(open("C:\\Users\\laiwu\\Desktop\\rmrb\\rmrb2020080101.pdf", "rb"))
# print how many pages input1 has:
print ("document1.pdf has %d pages." % input1.getNumPages())
输出结果:

这里需要强调的是:
PyPDF2 模块自带基础功能程序案例 https://github.com/mstamy2/PyPDF2/blob/master/Sample_Code/basic_features.py
但其中因为python程序升级的原因
案例程序中:
1、print 函数忘记 加括号。
2、子文件夹需要用“\\”来分隔。
使用PyPDF2操作PDF文件
本文介绍如何使用PyPDF2模块读取PDF文件并获取页数信息,演示了正确使用print函数及路径分隔符的方法,同时指出并修正了官方示例代码中的常见错误。
3768

被折叠的 条评论
为什么被折叠?



