feat: PDF text extraction and per-page classification#4
Merged
Conversation
Use pypdfium2 (permissively licensed, ships its own native library) so there is no system poppler dependency. Add fpdf2 as a dev dependency for test fixtures and a mypy override for the stub-less binding.
Add the Pdf handle (context-managed pypdfium2 document) and classify_pdf, which pulls each page's embedded text layer and runs it through the page classifier.
Build PDFs with fpdf2 and assert text extraction, page iteration, digital text pages, and a blank page classified as scanned.
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.
Wires the page classifier to real PDFs: pull each page's embedded text layer and classify it.
What
Pdf— a context-managed handle over a pypdfium2 document (len,page_text,page_texts), releasing native resources on exit.classify_pdf(path)— extracts every page's text and returns a per-pageClassification.Why pypdfium2
Permissively licensed and ships its own native PDFium library, so users install no system poppler. It also renders pages, which the OCR-fallback step will reuse.
Tests
Fixtures are generated in-process with
fpdf2(dev dependency): text extraction, multi-page iteration, text pages classifiedDIGITAL, and a blank page classifiedSCANNED.Notes
Verified locally: ruff, ruff format, mypy (strict), pytest (15) all pass.