您好,登錄后才能下訂單哦!
這篇文章主要介紹pdf用python讀取的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
python中可以使用pdfminer庫來讀取PDF文件中的內(nèi)容。
安裝命令:
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處理頁面內(nèi)容
PDFDevice將其翻譯成你需要的格式
PDFResourceManager用于存儲(chǔ)共享資源,如字體或圖像。
以上是pdf用python讀取的方法的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。