1、PDFParser:从一个文件中获取数据PDFDocument:保存获取的数据,和PDFParser是相互关联的PDFPageInterPReter处理页面内容PDFDevice将其翻译成你需要的格式PDFResourceManager用于存储共享资源,如字体或图像。
2、from ur盟敢势袂llib.request import urlopenfrom pdfminer.pdfinterp imp泠贾高框ort PDFResourceManager,process_pdffrom pdfminer.converter import TextConverterfrom pdfminer.layout import LAParamsfrom io import StringIOfrom io import opendef readPDF(pdffile): rsrcmgr=PDFResourceManager() retstr=StringIO() laparams=LAParams() device=TextConverter(rsrcmgr,retstr,laparams=laparams) process_pdf(rsrcmgr,device,pdffile) device.close() content=retstr.getvalue() retstr.close() return contentpdffile=urlopen('http://pythonscraping.com/pages/warandpeace/chapter1.pdf')outputString=readPDF(pdffile)print(outputString)pdffile.close()读取一个pdf文档。
3、LTPage :表示整个页。可能会含有LTTextBox,雉搽妤粲LTFigure,LTImage,LTRect,LTCurve和LTLine子对象。LTText蚱澄堆别Box:表示一组文本块可能包含在一个矩形区域。注意此box是由几何分析中创建,并且不一定表示该文本的一个逻辑边界。它包含LTTextLine对象的列表。使用 get_text()方法返回的文本内容。LTTextLine :包含表示单个文本行LTChar对象的列表。字符对齐要么水平或垂直,取决于文本的写入模式。get_text()方法返回的文本内容。LTCharLTAnno:在文本中实际的字母表示为Unicode字符串(?)。需要注意的是,虽然一个LTChar对象具有实际边界,LTAnno对象没有,因为这些是“虚拟”的字符,根据两个字符间的关系(例如,一个空格)由布局分析后插入。LTImage:表示一个图像对象。嵌入式图像可以是JPEG或其它格式,但是目前PDFMiner没有放置太多精力在图形对象。LTLine:代表一条直线。可用于分离文本或附图。LTRect:表示矩形。可用于框架的另一图片或数字。LTCurve:表示一个通用的Bezier曲线
4、from pdfminer.pdfparser import PDFParser, PDFDocumentfile=open(path, 'rb')parser=PDFParser(file)document=PDFDocument()parser.set_document(document)document.set_parser(parser)document.initialize(password)outlines=document.get_outlines()for (level,title,dest,a,se) in outlines: print (level, title,dest,a,se)输出pdf文件的等级,标题等参数
5、从官网下载软件,解压,并使用win+R cmd回车cd 文件路径python setup.py install