新聞中心
python中可以使用pdfminer庫(kù)來(lái)讀取PDF文件中的內(nèi)容。

為愛(ài)輝等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及愛(ài)輝網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為網(wǎng)站設(shè)計(jì)制作、做網(wǎng)站、愛(ài)輝網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!
安裝命令:
pip install pdfminer
pip install pdfminer3k
python中讀取PDF文件代碼:
from urllib.request import urlopen
from pdfminer.pdfinterp import PDFResourceManager, process_pdf
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from io import StringIO
from io import open
def 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 content
pdfFile = urlopen("http://pythonscraping.com/pages/warandpeace/chapter1.pdf")
outputString = readPDF(pdfFile)
print(outputString)
pdfFile.close()解析pdf文件用到的類:
PDFParser:從一個(gè)文件中獲取數(shù)據(jù)
PDFDocument:保存獲取的數(shù)據(jù),和PDFParser是相互關(guān)聯(lián)的
PDFPageInterpreter處理頁(yè)面內(nèi)容
PDFDevice將其翻譯成你需要的格式
PDFResourceManager用于存儲(chǔ)共享資源,如字體或圖像。
分享標(biāo)題:創(chuàng)新互聯(lián)Python教程:pdf如何用python讀???
轉(zhuǎn)載源于:http://m.5511xx.com/article/coeeppe.html


咨詢
建站咨詢
