Hướng dẫn how do i extract a specific word from a pdf in python? - làm cách nào để trích xuất một từ cụ thể từ pdf trong python?
Trích xuất văn bản từ PDF Python với các ví dụ về mã Show
Với bài viết này, chúng tôi sẽ kiểm tra một số trường hợp khác nhau về cách giải quyết văn bản trích xuất từ vấn đề PDF Python. # pip3 install pdfplumber import pdfplumber # a single page with pdfplumber.open(r'test.pdf') as pdf: first_page = pdf.pages[-0] print(first_page.extract_text()) # for every page # with pdfplumber.open(r'test.pdf') as pdf: # for pages in pdf.pages: # print(pages.extract_text()) Phần sau của mã cung cấp một bản tóm tắt ngắn gọn về nhiều phương pháp có thể được sử dụng để giải quyết văn bản trích xuất từ vấn đề PDF Python. # using PyMuPDF import sys, fitz fname = sys.argv[1] # get document filename doc = fitz.open(fname) # open document out = open(fname + ".txt", "wb") # open text output for page in doc: # iterate the document pages text = page.get_text().encode("utf8") # get plain text (is in UTF-8) out.write(text) # write text of page out.write(bytes((12,))) # write page delimiter (form feed 0x0C) out.close() Thông qua nhiều ví dụ, chúng tôi đã học cách giải quyết văn bản trích xuất từ vấn đề PDF Python. Bước 1: Nhập tất cả các thư viện. Bước 2: Chuyển đổi tệp PDF thành định dạng TXT và đọc dữ liệu. Bước 3: Sử dụng. Findall () Chức năng của các biểu thức chính quy để trích xuất các từ khóa. Có một vài thư viện Python sử dụng mà bạn có thể trích xuất dữ liệu từ PDFS. Ví dụ: bạn có thể sử dụng thư viện PYPDF2 để trích xuất văn bản từ các tệp PDF trong đó văn bản theo cách tuần tự hoặc được định dạng, tức là trong các dòng hoặc biểu mẫu. Bạn cũng có thể trích xuất các bảng trong các tệp PDF thông qua Thư viện Camelot.21-Jun-2021 Dễ dàng chỉnh sửa tài liệu PDF được quét của bạn với OCR. Với nhận dạng ký tự quang học (OCR) trong Adobe Acrobat, bạn có thể trích xuất văn bản và chuyển đổi các tài liệu được quét thành các tệp PDF có thể chỉnh sửa ngay lập tức. Sau đây là một quá trình từng bước để trích xuất dòng văn bản theo dòng từ PDF.
Làm cách nào để chọn một văn bản cụ thể trong PDF?Để trích xuất thông tin từ PDF trong Acrobat DC, hãy chọn Công cụ> Xuất PDF và chọn tùy chọn. Để trích xuất văn bản, xuất PDF sang định dạng từ hoặc định dạng văn bản phong phú và chọn từ một số tùy chọn nâng cao bao gồm: lưu lại văn bản chảy.10-FEB-2021 Làm cách nào để tìm kiếm một từ trong PDF bằng Python?“Tìm kiếm một từ trong pdf bằng cách sử dụng mã python của câu trả lời
# Nhận số trang. Numpages = đối tượng. getnumpages ()Bạn có thể trích xuất dữ liệu từ các tệp PDF trực tiếp vào Excel. Đầu tiên, bạn sẽ cần nhập tệp PDF của mình. Khi bạn nhập tệp, hãy sử dụng nút Dữ liệu trích xuất để bắt đầu quá trình trích xuất. Bạn sẽ thấy một số cửa sổ hướng dẫn sẽ giúp bạn trích xuất dữ liệu đã chọn.
Hãy nhớ lưu tệp PDF của bạn ở cùng một vị trí nơi bạn lưu tệp tập lệnh Python của mình.Bây giờ của bạn. Tệp PDF được tạo và lưu mà sau này bạn sẽ chuyển đổi thành a.
Bây giờ bạn sẽ thấy một khung Navigator hiển thị các bảng & trang trong tệp PDF của bạn cùng với bản xem trước.Chọn một bảng và nhấp vào Tải. Cải thiện bài viết Lưu bài viết Cải thiện bài viết Lưu bài viết ĐọcPortable Document Format. It uses .pdf extension. It is used to present and exchange documents reliably, independent of software, hardware, or operating system. Bàn luậnTất cả các bạn phải quen thuộc với PDFS là gì. Trên thực tế, chúng là một trong những phương tiện kỹ thuật số quan trọng và được sử dụng rộng rãi nhất. PDF là viết tắt của định dạng tài liệu di động. Nó sử dụng tiện ích mở rộng .pdf. Nó được sử dụng để trình bày và trao đổi tài liệu một cách đáng tin cậy, độc lập với phần mềm, phần cứng hoặc hệ điều hành. Lưu ý: Để biết thêm thông tin, hãy tham khảo làm việc với các tệp PDF trong Python For more information, refer to Working with PDF files in Python Cài đặtĐể cài đặt gói này, loại lệnh dưới đây trong thiết bị đầu cuối. pip install PyPDF2 Example: Đầu vào PDF:
# using PyMuPDF import sys, fitz fname = sys.argv[1] # get document filename doc = fitz.open(fname) # open document out = open(fname + ".txt", "wb") # open text output for page in doc: # iterate the document pages text = page.get_text().encode("utf8") # get plain text (is in UTF-8) out.write(text) # write text of page out.write(bytes((12,))) # write page delimiter (form feed 0x0C) out.close()0 # using PyMuPDF import sys, fitz fname = sys.argv[1] # get document filename doc = fitz.open(fname) # open document out = open(fname + ".txt", "wb") # open text output for page in doc: # iterate the document pages text = page.get_text().encode("utf8") # get plain text (is in UTF-8) out.write(text) # write text of page out.write(bytes((12,))) # write page delimiter (form feed 0x0C) out.close()1 # using PyMuPDF import sys, fitz fname = sys.argv[1] # get document filename doc = fitz.open(fname) # open document out = open(fname + ".txt", "wb") # open text output for page in doc: # iterate the document pages text = page.get_text().encode("utf8") # get plain text (is in UTF-8) out.write(text) # write text of page out.write(bytes((12,))) # write page delimiter (form feed 0x0C) out.close()2 # using PyMuPDF import sys, fitz fname = sys.argv[1] # get document filename doc = fitz.open(fname) # open document out = open(fname + ".txt", "wb") # open text output for page in doc: # iterate the document pages text = page.get_text().encode("utf8") # get plain text (is in UTF-8) out.write(text) # write text of page out.write(bytes((12,))) # write page delimiter (form feed 0x0C) out.close()3 # using PyMuPDF import sys, fitz fname = sys.argv[1] # get document filename doc = fitz.open(fname) # open document out = open(fname + ".txt", "wb") # open text output for page in doc: # iterate the document pages text = page.get_text().encode("utf8") # get plain text (is in UTF-8) out.write(text) # write text of page out.write(bytes((12,))) # write page delimiter (form feed 0x0C) out.close()4 # using PyMuPDF import sys, fitz fname = sys.argv[1] # get document filename doc = fitz.open(fname) # open document out = open(fname + ".txt", "wb") # open text output for page in doc: # iterate the document pages text = page.get_text().encode("utf8") # get plain text (is in UTF-8) out.write(text) # write text of page out.write(bytes((12,))) # write page delimiter (form feed 0x0C) out.close()5 # using PyMuPDF import sys, fitz fname = sys.argv[1] # get document filename doc = fitz.open(fname) # open document out = open(fname + ".txt", "wb") # open text output for page in doc: # iterate the document pages text = page.get_text().encode("utf8") # get plain text (is in UTF-8) out.write(text) # write text of page out.write(bytes((12,))) # write page delimiter (form feed 0x0C) out.close()6 # using PyMuPDF import sys, fitz fname = sys.argv[1] # get document filename doc = fitz.open(fname) # open document out = open(fname + ".txt", "wb") # open text output for page in doc: # iterate the document pages text = page.get_text().encode("utf8") # get plain text (is in UTF-8) out.write(text) # write text of page out.write(bytes((12,))) # write page delimiter (form feed 0x0C) out.close()7 # using PyMuPDF import sys, fitz fname = sys.argv[1] # get document filename doc = fitz.open(fname) # open document out = open(fname + ".txt", "wb") # open text output for page in doc: # iterate the document pages text = page.get_text().encode("utf8") # get plain text (is in UTF-8) out.write(text) # write text of page out.write(bytes((12,))) # write page delimiter (form feed 0x0C) out.close()8 # using PyMuPDF import sys, fitz fname = sys.argv[1] # get document filename doc = fitz.open(fname) # open document out = open(fname + ".txt", "wb") # open text output for page in doc: # iterate the document pages text = page.get_text().encode("utf8") # get plain text (is in UTF-8) out.write(text) # write text of page out.write(bytes((12,))) # write page delimiter (form feed 0x0C) out.close()9 # using PyMuPDF import sys, fitz fname = sys.argv[1] # get document filename doc = fitz.open(fname) # open document out = open(fname + ".txt", "wb") # open text output for page in doc: # iterate the document pages text = page.get_text().encode("utf8") # get plain text (is in UTF-8) out.write(text) # write text of page out.write(bytes((12,))) # write page delimiter (form feed 0x0C) out.close()2 pip install PyPDF21 pip install PyPDF22 pip install PyPDF23 pip install PyPDF24 # using PyMuPDF import sys, fitz fname = sys.argv[1] # get document filename doc = fitz.open(fname) # open document out = open(fname + ".txt", "wb") # open text output for page in doc: # iterate the document pages text = page.get_text().encode("utf8") # get plain text (is in UTF-8) out.write(text) # write text of page out.write(bytes((12,))) # write page delimiter (form feed 0x0C) out.close()2 pip install PyPDF26 pip install PyPDF27 # using PyMuPDF import sys, fitz fname = sys.argv[1] # get document filename doc = fitz.open(fname) # open document out = open(fname + ".txt", "wb") # open text output for page in doc: # iterate the document pages text = page.get_text().encode("utf8") # get plain text (is in UTF-8) out.write(text) # write text of page out.write(bytes((12,))) # write page delimiter (form feed 0x0C) out.close()8 pip install PyPDF22 pdfFileObj = open('example.pdf', 'rb')0 pdfFileObj = open('example.pdf', 'rb')1 Output: Hãy để chúng tôi cố gắng hiểu mã trên trong các khối:
|