Add PDFium backend and PDF operations API#9
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an optional PDFium (pypdfium2) backend and a page-level PDF operations flow (extract/delete/reorder/rotate) exposed end-to-end via backend routes, frontend API types, and tests. This fits into the existing src/pdf/ modularization by introducing an engine abstraction and adding derived-PDF artifacts alongside raw.pdf.
Changes:
- Introduce
src/pdf/engine.pyabstraction with PyMuPDF (default) and PDFium implementations; refactor extraction/rendering to use the configured engine. - Add PDF operations module and new API routes to create and download derived PDFs with manifests.
- Add web API typings/helpers plus focused pytest coverage and supporting documentation/env/packaging updates.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| web/src/api/types.ts | Adds PdfOperationResult type for derived PDF operation responses. |
| web/src/api/docs.ts | Adds client helpers for creating PDF operations and downloading derived PDFs. |
| tests/test_routes_web.py | Adds route-level tests for creating and fetching derived PDFs. |
| tests/test_pdfium_engine.py | Adds PDFium engine + operations unit tests (skipped if pypdfium2 missing). |
| src/pdf/render.py | Refactors rendering to delegate to the configured PDF engine. |
| src/pdf/operations.py | Implements PDFium-backed page-level operations (extract/delete/reorder/rotate/merge). |
| src/pdf/extractor.py | Refactors extraction to delegate to the configured PDF engine; keeps compatibility wrapper. |
| src/pdf/engine.py | New engine abstraction + implementations for PyMuPDF and PDFium. |
| src/api/routes.py | Adds PDF operations and derived-PDF download routes and request model. |
| pyproject.toml | Adds optional dependency group pdfium and includes it in all. |
| docs/pdf_engine_evaluation.md | Adds evaluation/decision doc for PDF engines and editing approach. |
| docs/architecture_and_capabilities.md | Updates architecture docs to include engine abstraction and operations routes/module. |
| .env.example | Documents new PDF_ENGINE environment variable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+191
to
+194
| if render_path: | ||
| img_path = render_path / f"page_{idx + 1:04d}.png" | ||
| self._save_page_bitmap(page, img_path, dpi=200) | ||
| images.append(str(img_path)) |
Comment on lines
+254
to
+266
| def _save_page_bitmap(page, img_path: Path, *, dpi: int) -> None: | ||
| bitmap = page.render( | ||
| scale=dpi / 72.0, | ||
| draw_annots=True, | ||
| fill_color=(255, 255, 255, 255), | ||
| optimize_mode="lcd", | ||
| ) | ||
| try: | ||
| bitmap.to_pil().save(str(img_path)) | ||
| finally: | ||
| close = getattr(bitmap, "close", None) | ||
| if close is not None: | ||
| close() |
Comment on lines
+341
to
+342
| if not str(derived_dir).startswith(str(root)): | ||
| return _err("bad_request", "Invalid derived artifact path") |
|
|
||
| ### PDFium Backend PoC | ||
|
|
||
| - Add optional dependency group, for example `pdfium = ["pypdfium2>=4"]`. |
| **3. PDF 处理层** | ||
| - `src/pdf/extractor.py` — PyMuPDF 文本抽取 + PDF 格式校验(`%PDF-` 头部检测) | ||
| - `src/pdf/engine.py` — PDF 引擎抽象,默认 PyMuPDF,可通过 `PDF_ENGINE=pdfium` 切换到 pypdfium2/PDFium | ||
| - `src/pdf/extractor.py` — 基于配置引擎的文本抽取 + PDF 格式校验(`%PDF-` 头部检测) |
magic-alt
added a commit
that referenced
this pull request
Jun 6, 2026
Add PDFium backend and PDF operations API
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
Add the PDFium evaluation and document-operations work needed to support extract/delete/reorder/rotate flows end to end.
Testing