Open
Conversation
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.
How It Works
User submits a PDF URL (e.g., https://upload.wikimedia.org/wikipedia/commons/.../file.pdf) at /pdf
PDF is downloaded and each page rendered to a PNG image via Imagick
Each page image is classified using contour analysis:
Text pages: only small text-like regions detected
Image+Text pages: mix of large image regions and small text regions
Image pages: only large image regions (these are skipped for OCR)
Only Text and Image+Text pages are sent to the selected OCR engine
Results show per-page classifications, per-page text, and combined full text
API Usage
GET /api/pdf?image=<PDF_URL>&engine=google&langs[]=en&start_page=1&end_page=10
Returns JSON with per-page classifications, OCR text, and summary.
To Run
Install Imagick (macOS)
pecl install imagick
brew install ghostscript
Or use Docker
./docker/setup.sh && ./docker/run.sh
Then visit http://localhost:8000/pdf
New Files Created
PdfProcessor.php - Core PDF processing service that:
Downloads PDFs from Wikimedia Commons URLs
Converts PDF pages to images using Imagick (ImageMagick)
Classifies each page as Text, Image, or Image+Text using GD-based contour analysis (ported from the Python app.py logic)
Uses flood-fill connected component analysis at 1/4 resolution for performance
Supports page range filtering (start_page, end_page)
PdfPageClassification.php - Immutable DTO for a classified page (page number, type, image data, hasText() helper)
PdfResult.php - Immutable DTO for the full PDF result (page classifications, per-page OCR text, combined text, warnings, helpers for OCR'd/skipped pages)
PDF processing with:
PDF URL input with page range options
Engine and language selection
Processing summary (total/OCR'd/skipped pages)
Page classification table with color-coded labels
Per-page text output in expandable panels
Full combined text with copy-to-clipboard
will further try imrpving the ui and make the code more modular and try fixing:
-Possible crash in Transkribus line model mapping (missing key handling)
-Transkribus polling loop has no timeout (can block indefinitely)
-OCR response uses JSON_NUMERIC_CHECK which can corrupt numeric text
-Image URL validation isn’t strict enough (edge cases + SSRF risk)