-
Notifications
You must be signed in to change notification settings - Fork 5.9k
fix(frontend/pdfjs): ensure CID character rendering via CMaps & stabilize PDF compare/preview #4762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Standardizes PDF.js configuration across all JS modules and templates by introducing a PDFJS_DEFAULT_OPTIONS object and using a dynamic pdfjsPath for worker and font resources. Updates all PDF.js usages to use the new options, improving compatibility and font loading. Enhances the PDF comparison tool with better error handling, robust file validation, improved worker communication, and more user-friendly feedback for large or invalid files. Also fixes minor issues such as relative file path in homecard.js and button event handling in compare.html.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors PDF.js usage across the application to improve reliability and maintainability. The changes introduce centralized PDF.js configuration with CMap and font options, update worker path references to use a global pdfjsPath variable, and enhance error handling in the PDF comparison feature.
- Centralized PDF.js configuration with
PDFJS_DEFAULT_OPTIONSacross multiple files - Updated PDF.js worker paths from hardcoded strings to use
pdfjsPathvariable - Improved error handling and validation in PDF comparison feature
- Refactored PDF comparison worker to use diff.js library instead of custom LCS algorithm
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| rotate-pdf.html | Added module import for PDF.js and PDFJS_DEFAULT_OPTIONS configuration |
| misc/compare.html | Major refactor: added error handling, PDF validation, worker timeout, and improved structure |
| merge-pdfs.html | Updated worker path to use pdfjsPath variable |
| fragments/navbar.html | Defined global pdfjsPath constant for consistent path resolution |
| convert/pdf-to-pdfa.html | Updated worker path to use pdfjsPath variable |
| js/pages/*.js | Added PDFJS_DEFAULT_OPTIONS and updated worker paths in sign, pdf-to-csv, crop, change-metadata, adjust-contrast, add-image files |
| js/multitool/PdfContainer.js | Added PDFJS_DEFAULT_OPTIONS and updated PDF loading |
| js/merge.js | Added PDFJS_DEFAULT_OPTIONS and worker path update |
| js/homecard.js | Fixed fetch path from absolute to relative |
| js/downloader.js | Added PDFJS_DEFAULT_OPTIONS and updated worker paths |
| js/compare/pdfWorker.js | Refactored to use diff.js library, improved message handling, and enhanced batching logic |
| js/DecryptFiles.js | Added PDFJS_DEFAULT_OPTIONS to decrypt operations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Refines the batching logic in pdfWorker.js to handle overlaps and processed word tracking more accurately, reducing duplicate processing and improving diff granularity. Also exposes pdfjsLib as a global variable in rotate-pdf.html for easier access in other scripts.
Pass the status element to the extractText function to update progress dynamically for each file, simplifying the code and improving maintainability.
Description of Changes
What was changed
PDFJS_DEFAULT_OPTIONSobject and applied it across frontend modules using PDF.js:cMapUrl,cMapPacked, andstandardFontDataUrlso PDF.js can correctly load CMaps and standard fonts.GlobalWorkerOptions.workerSrcusages to the dynamicpdfjsPath + 'pdf.worker.mjs'.pdfjsPathglobally innavbar.htmlto support deployments under subpaths/reverse proxies.DecryptFiles.js,downloader.js,merge.js, Multi-Tool (PdfContainer.js), and feature pages (add-image.js,adjust-contrast.js,change-metadata.js,crop.js,pdf-to-csv.js,sign.js,rotate-pdf.html,convert/pdf-to-pdfa.html,merge-pdfs.html).type: 'COMPARE' | 'SET_*') and safer logs.disableWorker: true) to prevent rendering failures../files/popularity.txt) to respect base paths.Why the change was made
pdfjsPathand using it consistently fixes this.Closes #4391
Checklist
General
Documentation
UI Changes (if applicable)
Testing (if applicable)