Seitenzahl in PYMUPDF Multiprocessing mit extract_textPython

Python-Programme
Anonymous
 Seitenzahl in PYMUPDF Multiprocessing mit extract_text

Post by Anonymous »

In der Dokumentation von PYMUPDF heißt es also, dass PYMUPDF auf mehreren Threads nicht unterstützt wird.

Code: Select all

    seg_size = int(num_pages / cpu + 1)
seg_from = idx * seg_size
seg_to = min(seg_from + seg_size, num_pages)
for i in range(seg_from, seg_to):  # work through our page segment
page = doc[i]
# page.get_text("rawdict")  # use any page-related type of work here, eg

< /code>
Warum nicht zuerst das Dokumenten laden-> Anzahl der Seiten abrufen und dann die Nummer an die Handler-Funktion geben? Anstatt Segmente wie im Beispielcode zu verwenden? Würde dies Probleme verursachen?def extract_text_from_page(args: Tuple[bytes, int]) -> Tuple[int, str]:
pdf_stream, page_num = args
# Open a new Document instance in this process
doc = pymupdf.open(stream=pdf_stream)
page = doc.load_page(page_num)  # Load the specific page
text = page.get_text(sort=True)  # Extract text with sorting
doc.close()  # Clean up
return (page_num, text)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post