Skip to content

Commit a7cd5b2

Browse files
committed
Use tqdm for robust progress bar
1 parent f656c7a commit a7cd5b2

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

pymupdf4llm/pymupdf4llm/helpers/pymupdf_rag.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import os
3030
import string
31+
from tqdm import tqdm
3132

3233
try:
3334
import pymupdf as fitz # available with v1.24.3
@@ -764,10 +765,10 @@ def get_page_output(doc, pno, margins, textflags):
764765
# read the Table of Contents
765766
toc = doc.get_toc()
766767
textflags = fitz.TEXT_MEDIABOX_CLIP | fitz.TEXT_CID_FOR_UNKNOWN_UNICODE
768+
if show_progress:
769+
print(f"Processing {doc.name}...")
770+
pages = tqdm(pages)
767771
for pno in pages:
768-
if show_progress:
769-
print(f"Processing page {pno} of {len(pages)}...", end=" ", flush=True)
770-
771772
page_output, images, tables, graphics = get_page_output(
772773
doc, pno, margins, textflags
773774
)
@@ -788,9 +789,6 @@ def get_page_output(doc, pno, margins, textflags):
788789
"text": page_output,
789790
}
790791
)
791-
792-
if show_progress:
793-
print("Processed!")
794792

795793
return document_output
796794

pymupdf4llm/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"Programming Language :: Python :: 3",
1414
"Topic :: Utilities",
1515
]
16-
requires = ["pymupdf>=1.24.2"]
16+
requires = ["pymupdf>=1.24.2", "tqdm>=4.66.5"]
1717

1818
setuptools.setup(
1919
name="pymupdf4llm",

0 commit comments

Comments
 (0)