feat(pdf): add to_markdown_pages for per-page extraction - #91
Open
HaoChiBao wants to merge 2 commits into
Open
Conversation
Expose a thin wrapper over pdf-inspector's page API so callers get page boundaries and OCR flags without forcing PDFs through the document model (Closes firecrawl#62).
There was a problem hiding this comment.
All reported issues were addressed across 4 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MarkdownPageplusto_markdown_pages/to_markdown_pages_byteswrapping pdf-inspector's per-page extraction (page boundaries, OCR flags)to_documentunsupported; leave existing single-blobto_markdown/to_markdown_bytesbehavior unchangedCloses #62
Why not
to_documentfor PDFPDFs intentionally bypass the document model (pdf-inspector emits Markdown directly). A thin per-page API is the low-risk path from the issue and does not race the OCR work in #61.
Test plan
cargo fmt --allcargo clippy --locked --all-targets -- -D warningscargo test --locked(fixturetests/fixtures/pdf/text.pdf)Summary by cubic
Adds per-page Markdown extraction for PDFs so callers can keep page boundaries and detect OCR needs. Previously we only returned a single Markdown blob and errored on fully scanned PDFs; now
to_markdown_pages/to_markdown_pages_bytesreturn one item per page with aneeds_ocrflag, while single-blob APIs remain unchanged.Exposes
MarkdownPage { page, markdown, needs_ocr, ocr_reason }and exports it from the crate.Keeps
to_markdown/to_markdown_bytesbehavior: still one string; still errors on image-only PDFs and logs when some pages need OCR.Adds
to_markdown_pages/to_markdown_pages_bytes: never fail solely due to OCR; pages that need OCR have emptymarkdownandneeds_ocr = trueand may includeocr_reason. Logs a warn when any pages need OCR.Leaves
to_documentunsupported forFormat::Pdf; updates theUnsupportedmessage to mentionto_markdown_pages.Updates README and adds a basic per-page test.
Migration (optional): If you need page boundaries or to route OCR per page, switch PDF callers to
to_markdown_pages/to_markdown_pages_bytes. Otherwise, keep usingto_markdown/to_markdown_bytes.Written for commit 5d0c50f. Summary will update on new commits.