from io import StringIOfrom pdfminer.pdfinterp import PDFResourceManager,process_pdffrom pdfminer.converter import TextConverterfrom pdfminer.layout import LAParamspdf_file=open("程序设计训练课程指导书-Henry.pdf",'rb')man=PDFResourceManager()#资源管理str=StringIO()#字符流lap=LAParams()#层参数device=TextConverter(rsrcmgr=man,laparams=lap,outfp=str)process_pdf(rsrcmgr=man,device=device,fp=pdf_file) #读取pdf 到内存中device.close()content=str.getvalue() #利用输入输出流 获取 内容str.close()pdf_file.close()print(content) #打印#写入 txt文本中 方便 操作with open("res.txt","w",encoding='utf-8')as f: f.write(content) #打开文本 存字符串到文本 f.close()#关闭文本对象
实验 环境:win10,python3.7
显示:没有限制 快速
存入文件: