Create test_PDFandJPG.py
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import pymupdf
|
||||
import io
|
||||
from PIL import Image
|
||||
import pytesseract
|
||||
|
||||
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
|
||||
|
||||
def extrahiere_text_und_bilder(pdf_datei):
|
||||
doc = pymupdf.open(pdf_datei)
|
||||
text = ""
|
||||
for seite in doc:
|
||||
text += seite.get_text()
|
||||
for bild in seite.get_images(full=True):
|
||||
xref = bild[0]
|
||||
basis_bild = doc.extract_image(xref)
|
||||
bild_daten = basis_bild["image"]
|
||||
bild_objekt = Image.open(io.BytesIO(bild_daten))
|
||||
bild_text = pytesseract.image_to_string(bild_objekt, lang="deu")
|
||||
text += " " + bild_text
|
||||
return text
|
||||
|
||||
pdf_datei = 'any.pdf'
|
||||
text = extrahiere_text_und_bilder(pdf_datei)
|
||||
|
||||
print(text)
|
||||
Reference in New Issue
Block a user