Skip to content

fix: add page progress callback to to_markdown - #479

Open
JackyHsu-X wants to merge 3 commits into
pymupdf:mainfrom
JackyHsu-X:fix/progress-callback-288
Open

JackyHsu-X wants to merge 3 commits into
pymupdf:mainfrom
JackyHsu-X:fix/progress-callback-288

Conversation

@JackyHsu-X

@JackyHsu-X JackyHsu-X commented Sep 27, 2026 •

Copy link
Copy Markdown

Summary

  • Add an optional progress_callback(done, total) to to_markdown() without adding a dependency.
  • Report progress after each selected page is parsed in Layout mode or rendered in legacy mode. Counts are 1-based completed pages; total is the number of selected pages.
  • Preserve upstream's placeholder-package migration and installation notes, and document the callback as an API of the embedded 4LLM source. Regression tests generate a PDF and select non-contiguous pages in both modes.

Why

Applications with their own UI cannot use the text printed by show_progress to update a progress indicator. The callback lets them report conversion progress directly. Fixes #288.

Validation

  • Merged-source Layout and legacy callback regression: 2 passed.
  • Expanded callback/conversion/chunking/table tests: 96 passed, 3 skipped, exit code 0. Optional integrations are not all installed.
  • All 35 Python source files parse and match the validated candidate hashes; contribution delta and git diff --check verified.

Validation reused an existing Windows PyMuPDF 2.0 / MuPDF 1.28.5 native-wheel environment. PyMuPDF Python code was loaded from the existing checkout e0bcbee because the installed wheel alone lacks the deferred-layout API required by current 4LLM main; native extensions and generated version metadata came from the existing wheel. All 4LLM source came from this branch's merge candidate, and its version guard remained enabled. No dependencies were installed, native extensions rebuilt, or runtime APIs monkeypatched. These source/native combination results do not claim a newly built PyMuPDF wheel or the Aptest/platform matrix passed. --noconftest avoids the repository's automatic optional-dependency upgrade hook.

Upstream integration

The branch incorporates main 030a6b0 without rebasing. The README is the only textual merge conflict: both upstream installation guidance and the embedded-source callback example are preserved. Upstream deferred imports, placeholder version 2.1 and removal of the obsolete Layout test are retained. Relative to this upstream, the contribution remains five files, 60 additions / 2 deletions, with no CI changes or new dependencies.

AI assistance was used to prepare the patch, integration and validation.

@JorjMcKie

Copy link
Copy Markdown
Collaborator

Thanks for submission - we really appreciate this.
Two comments:

  • Please read our CLA (Contributor License Agreement) located here and declare your agreement to it by adding a comment to your post worded: "I have read the Artifex Contributor License Agreement) and declare my agreement with it."
  • We are currently preparing a major release which requires our full attention. We therefore cannot deal with your suggestion within the next two or so weeks. Please bear with us.

@JorjMcKie
JorjMcKie self-requested a review September 29, 2026 16:42
@JackyHsu-X

Copy link
Copy Markdown
Author

I have read the Artifex Contributor License Agreement and declare my agreement with it.

@JackyHsu-X

Copy link
Copy Markdown
Author

Integrated in f33a0f1.

Updated the branch for upstream d9b212b while preserving the new placeholder-package README and the existing progress_callback(done, total) implementation. This keeps the source changes in the repository consumed by PyMuPDF's PYMUPDF_SETUP_PATH_4LLM build integration. The upstream removal of the old CLI entry point and other upstream changes are retained.

The only textual merge conflict was in README.md. Its package-migration note is preserved, with the callback example explicitly described as an API of the embedded 4LLM source. Relative to current main, the contribution remains five files, with no CI changes or added dependencies.

Validation:

  • Both callback cases pass using the merged source, including Layout and legacy conversion and a non-contiguous page selection.
  • All 35 Python source files parse; the source snapshot and contribution file list were verified, and git diff --check passes.
  • The selected callback/conversion/chunking tests pass: 76 passed, 3 skipped, exit code 0. Skips require the optional tiktoken, LlamaIndex and LangChain integrations that are not installed in the local environment.

The tests load the merged source directly with the existing PyMuPDF 1.28.2 native environment and its generated version metadata. No dependencies were installed, no version check was bypassed, and the test runner avoids the repository hook that automatically upgrades optional dependencies. The Aptest/native-2.x/platform matrix was not run locally; these results do not claim PyMuPDF 2.x wheel or CI success.

AI assistance was used to prepare the integration and run validation.

@JackyHsu-X

Copy link
Copy Markdown
Author

Updated the branch for main 030a6b0, retaining upstream's deferred imports, placeholder version update and obsolete Layout-test removal. The only textual conflict was in README.md; both the upstream migration/installation note and the embedded-source callback example are preserved. The callback parser code and regression tests are unchanged. Relative to current main, the contribution remains five files, 60 additions / 2 deletions.

The merged candidate passes both callback cases and the expanded related conversion/chunking/table group: 96 passed, 3 skipped. All 35 source files parse and match the validated snapshot, and git diff --check passes.

Validation used the existing Windows PyMuPDF 2.0 / MuPDF 1.28.5 native-wheel environment with Python PyMuPDF source from checkout e0bcbee, which provides the deferred-layout API absent from the installed wheel. The 4LLM source is the actual merged candidate, with existing generated version metadata and its version guard enabled. No dependencies were installed or native libraries rebuilt. This is a source/native combination test, not a newly built wheel or Aptest/platform-matrix result. The runner avoids the repository hook that automatically upgrades optional dependencies.

AI assistance was used to prepare and validate this integration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Instead of printing progress in to_markdown(), pass the progress

2 participants