Add single-page Image & PDF OCR extractor (Tesseract.js + PDF.js)#1
Add single-page Image & PDF OCR extractor (Tesseract.js + PDF.js)#1maddix123 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8207f7c5a3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const renderPdfPreview = async (file) => { | ||
| const arrayBuffer = await file.arrayBuffer(); | ||
| const pdf = await pdfjsLib.getDocument({ data: arrayBuffer }).promise; |
There was a problem hiding this comment.
Configure pdf.js worker before calling getDocument
Because the page loads pdfjs-dist from a CDN but never sets pdfjsLib.GlobalWorkerOptions.workerSrc, pdfjsLib.getDocument(...) can fail in common browser setups with the “No GlobalWorkerOptions.workerSrc specified” / worker load error, which means PDF previews and OCR never run. This regression only shows up for PDF uploads (images still work), but in that scenario the promise in renderPdfPreview and extractFromPdf rejects before any pages render, leaving users stuck without an actionable status update.
Useful? React with 👍 / 👎.
Motivation
Tesseract.jsfor OCR andpdfjs-distfor PDF rendering.Description
index.htmlcontents with a complete HTML/CSS/JS single-page app that implements the OCR UI and flows.pdfjs-distandtesseract.jsand implementedextractFromImage,extractFromPdf, andextractTextfunctions to perform OCR on images and each PDF page.img, and UI controls forExtract,Clear, andCopy to Clipboard.Testing
python -m http.server 8000, which started serving the app successfully.mcp__browser_tools__run_playwright_script), but the Chromium process crashed so the capture failed.Codex Task