Add pypdf-compatible wrapper powered by LiteParse#53
Open
Conversation
New Python package that wraps liteparse input/output into the pypdf interface (PdfReader, PageObject, DocumentInformation) so it can be used as a drop-in replacement in any codebase that currently uses pypdf. https://claude.ai/code/session_0115fTqokYpxd7kJY2j5wZwB
extract_text() still uses LiteParse for higher quality spatial reconstruction. Everything else (metadata, images, annotations, outlines, form fields, page manipulation, etc.) now falls through to the real pypdf library. Re-export PdfWriter, error classes, and DocumentInformation from pypdf for full drop-in compatibility. https://claude.ai/code/session_0115fTqokYpxd7kJY2j5wZwB
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
This PR introduces a new
liteparse-pypdf-compatiblepackage that provides a drop-in replacement for thepypdflibrary. The wrapper enhances text extraction using LiteParse's spatial reconstruction engine while delegating all other PDF operations (metadata, images, annotations, form fields, etc.) to the underlying pypdf library.Key Changes
New
PdfReaderclass (_reader.py): A pypdf-compatible reader that combines LiteParse parsing for text extraction with pypdf's full feature set. Supports file paths, file-like objects, and bytes as input. Includes context manager support and proper cleanup of temporary files.New
PageObjectclass (_page.py): A pypdf-compatible page wrapper that:text_itemsandbounding_boxesMinimal
_RectangleObjectfallback: A lightweight rectangle implementation for page boxes when no pypdf page is available, supporting standard box properties (left, bottom, right, top, width, height) and indexing.Re-exports from pypdf: Makes commonly used pypdf classes available directly from
liteparse_pypdf(PdfWriter, DocumentInformation, error classes) to minimize import changes for users.Comprehensive test suite (
test_reader.py): 382 lines of tests covering:Documentation (
README.md): Usage guide explaining the drop-in replacement approach, what's enhanced vs delegated, LiteParse-specific options, and available extras.Package configuration (
pyproject.toml): Project metadata, dependencies (liteparse ≥1.0.0, pypdf ≥3.0.0), and development tools.Notable Implementation Details
__del__and context managerhttps://claude.ai/code/session_0115fTqokYpxd7kJY2j5wZwB