[英]How to read the pdf file in a line by line string in Python/Django?
[英]how to read the PDF file in a line by line in Python?
我在 python 2.7 中逐行閱讀 PDF 文件時遇到問題我想分別閱讀每一行並打印它們,我以前使用過但無法使用的本網站中的解決方案。
我試試這段代碼
import PyPDF2
pdfFileObj = open('c:\python\anms.pdf','rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
pdfReader.numPages
pageObj = pdfReader.getPage(0)
pageObj.extractText()
但是此代碼提取 PDF 中的所有字符串我想提取所有字符串但不是逐行提取所有字符串。
導入 PyPDF2
pdfFileObj = open('c:\python\anms.pdf','rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
pdfReader.numPages
pageObj =pdfReader.getPage(0)
pageObj.extractText()
但是這段代碼提取PDF中的所有字符串我想提取所有字符串但逐行提取。
你可以通過將它保存在一個大字符串中來做到這一點
text = pageObj.extractText()
然后拆分每一行
lines = text.split("\n")
如果你想打印每一行只是遍歷列表,這會將每一行保存為列表lines
中的一個元素
for i in lines:
print(i)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.