Python实现PDF指定页提取

通常我们在工作当中,有时候需要提取PDF文件中的指定出来 , 一般需要会员或者在网上寻找其他工具才能完成 , 需要耗费大量的时间和精力 。


Python实现PDF指定页提取



为了应对这种情况 , 使用Python的PyPDF2模块编写了一个小程序来完成提?。?
Python实现PDF指定页提取

运行日志
Python实现PDF指定页提取

【Python实现PDF指定页提取】生成的文件
print("页码:以逗号(,)分割,连续页码以连字符(-)分割 。")pages =input("请输入需要提取的页码:")try:pagelist = deal_page(pages)print(">>>>即将提取的页码如下:")print(pagelist)output = PdfFileWriter()pdf_file = PdfFileReader(open("AAAAAAAA.PDF", "rb"))pdf_pages_len = pdf_file.getNumPages()for i in pagelist:output.addPage(pdf_file.getPage(i-1))outputStream = open("output.pdf", "wb")output.write(outputStream)outputStream.close()print(">>>>恭喜你,PDF已提取完成 , 快去看看吧!<<<<")input("输入Enter键退出...")except Exception as e:print(">>>>请正确输入页码<<<<")print(e)
大家一般是如何提取PDF特定页的呢,欢迎评论区留言 。

相关经验推荐