Public API exposes no per-page text — DocumentResult.pages exists but isn't returned by process()/extract_json()
pdfmux version: observed on 1.6.4 (latest installed here). v1.7.0 is the current release, but its notes state the programmatic API defaults are Unchanged, so this is expected to persist — happy to confirm on 1.7.0 if useful. Python: 3.12
Summary
There is no public way to get per-page text out of pdfmux, even though the
library clearly models it internally. process() returns a ConversionResult
that has only a single combined text blob (plus a page_count integer), and
extract_json() / chunk() collapse a multi-page digital PDF into a single
page/chunk entry. Meanwhile the library ships a DocumentResult dataclass whose
pages field is a list[PageResult], and PageResult already carries exactly
the per-page data consumers need:
PageResult fields: page_num, text, confidence, quality, extractor,
image_count, ocr_applied, tables, key_values,
cost_usd, tokens_used
DocumentResult fields: pages, source, confidence, extractor_used, format,
text, warnings, ocr_pages, total_cost_usd,
total_tokens, has_arabic
ConversionResult fields: text, format, confidence, extractor_used,
page_count, warnings, classification, ocr_pages
So the per-page structure exists (DocumentResult.pages → PageResult.text /
.page_num / .confidence), but no public entry point returns a populated
DocumentResult, and the pymupdf4llm (digital) extractor path doesn't seem to
populate per-page text at all.
Why this matters
Per-page text is the basis for page-accurate provenance in a RAG pipeline:
attributing each retrieved chunk to a source page, inserting page-boundary
markers, and (in our case) iterating figures/tables per page. With only a single
blob + a page_count integer, none of that is possible without re-running a
separate extractor and trying to re-derive page boundaries — which defeats the
point of pdfmux owning routing/extraction.
Reproduction
import pymupdf, pdfmux
from pdfmux import pipeline
# Build a clean 3-page digital PDF, one distinct paragraph per page.
doc = pymupdf.open()
for t in ["Page one paragraph.", "Page two paragraph.", "Page three paragraph."]:
pg = doc.new_page()
pg.insert_textbox(pymupdf.Rect(72, 72, 520, 720), t, fontsize=12)
doc.save("three.pdf")
r = pipeline.process(file_path="three.pdf", output_format="markdown", quality="standard")
print("page_count:", r.page_count) # -> 3 (correct)
print("has .pages:", hasattr(r, "pages")) # -> False
# ConversionResult.text is one combined blob; no per-page split.
ej = pdfmux.extract_json("three.pdf")
print("extract_json pages:", len(ej["pages"])) # -> 1 (expected 3)
ch = pdfmux.chunk("three.pdf", max_tokens=200)
print("chunk page spans:", [(c["page_start"], c["page_end"]) for c in ch])
# -> [(1, 1)] for the whole document; all content reported as page 1
Observed on 1.6.4: page_count is correct (3), but process() has no pages,
extract_json()["pages"] has length 1, and chunk() reports
page_start == page_end == 1 for the entire document. extractor_used is
pymupdf4llm.
Expected
A public way to obtain per-page text, e.g. one of:
process(...)populates a per-page field (theDocumentResult.pageslist ofPageResult, each withpage_num+text+confidence), or returnsDocumentResult(or a flag likeprocess(..., per_page=True)); and/orextract_json()["pages"]/chunk()actually segment per page for the pymupdf4llm (digital) path, as they presumably already do for the Docling path.
The minimal contract that would unblock downstream provenance work:
per-page text, the source page_num, and per-page confidence — i.e. a
populated DocumentResult.pages.
Notes
pymupdf4llm.to_markdown(doc, page_chunks=True)returns correct per-page markdown in ~0.24s, so the underlying extractor already produces per-page output — it just isn't surfaced through pdfmux's public API.- This looks like a regression or refactor: downstream code (ours) was written
against
result.pages, which suggests some prior/related API exposed it.
Closing this — 1.7.0 already provides public per-page text, so the core ask is met. I'd missed it when filing.
pdfmux.streaming.process_streaming(file_path, quality) yields per-page events carrying exactly the "minimal contract" requested — page_num, text, and confidence (plus quality/extractor/ocr_applied), with a classified event first and a complete event last. There's also a pdfmux stream CLI command over the same generator. I verified the per-page output is 98.8–100% identical to process() on born-digital and simple-table PDFs, and it routes through the same pymupdf4llm.to_markdown path, so it's a faithful per-page view of the digital extractor.
Two small notes that may be worth a glance:
- Root cause of the mistaken version in this report:
pdfmux.__version__reports1.6.4even on a 1.7.0 install (pip show pdfmuxcorrectly says1.7.0). That stale attribute is what led me to file against "1.6.4". Might be worth syncing__version__to the released version. - Optional, not a request:
process()'s multi-pass / Docling-table output still has no per-page equivalent —process_streamingis pymupdf4llm-only, so it can diverge fromprocess()for table-heavy docs atquality=standard. A futureprocess(..., per_page=True)that exposes the multi-passPageResults would close that last gap, butprocess_streamingcovers the realistic cases for now.
Thanks for the library — resolving as already-addressed by process_streaming.