簡體   English   中英

我們如何使用python從pdf中提取特定值?

[英]How can we extract the specific value from pdf using python?

有沒有辦法使用 NLP 或 python 庫從 pdf 中獲取特定文本

首先使用以下命令安裝 PyPDF2 庫:

pip install PyPDF2

輸入以下代碼:

Import PyPDF2
mypdf=open(”/home/Desktop/sample.pdf”, mode=”rb”)
pdf_document=PyPDF2.PdfFileReader(mypdf) `

現在將pdfobject創建為pdf_document,pdf中有多少頁面然后使用pdf_document.numPages

first_page=pdf_document.getPage(0) print( first_page.extractText() )

現在你可以閱讀pdf文件了。

如果您對我的回答有任何誤解,請參考以下鏈接:

用於 NLP 的 Python:處理文本和 PDF 文件

您可以使用 tika、textract 或 PyPDF2

from tika import parser
data = parser.from_file('your_pdf.pdf')
print(data['text'])

嘗試pdfreader從 PDF 文檔中提取文本(純文本和包含 PDF 運算符)

這是從所有文檔頁面中提取上述所有內容的示例代碼。

from pdfreader import SimplePDFViewer, PageDoesNotExist

fd = open(you_pdf_file_name, "rb")
viewer = SimplePDFViewer(fd)

plain_text = ""
pdf_markdown = ""
try:
    while True:
        viewer.render()
        pdf_markdown += viewer.canvas.text_content
        plain_text += "".join(viewer.canvas.strings)
        viewer.next()
except PageDoesNotExist:
    pass

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM