pdf.js
AGENTS.md54k starsChanged 21 months agoApache-2.0View on GitHub
PDF.js is a Portable Document Format (PDF) viewer built with JavaScript, HTML5 Canvas, and CSS. It's a Mozilla project that provides a general-purpose, web standards-based platform for parsing and rendering PDFs without requiring native code or plugins. Then open http://localhost:8888/web/viewer.html to view the PDF viewer. Test PDFs are available at http://localhost:8888/test/pdfs/?frame Build for modern browsers: This generates pdf.js and pdf.worker.js in build/generic/build/. Build for distribution (creates pdfjs-dist package): Run all tests: Run unit tests only: Run integration tests (browser-based tests…
We split this AGENTS.md into the rules it gives an agent
14 rules. About 0 are common, 9 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 35
Run unit tests only:
- Distinctive: line 40
Run integration tests (browser-based tests using Puppeteer):
- Very specific: line 50
Run a single test file by modifying test/test_manifest.json or using test runner options.
- Distinctive: line 66
Run TypeScript type checking:
- Distinctive: line 158
When adding features that span multiple layers:
- Very specific: line 159
Start with the core layer if parsing/interpretation changes are needed
- Very specific: line 160
Update the display layer API if new capabilities need exposure
- Distinctive: line 162
Ensure worker communication handles new message types
- Very specific: line 179
Test PDFs downloaded from manifest (test/test_manifest.json)
- Distinctive: line 187
No semicolons required (ASI enabled)
- Distinctive: line 192
Keep PRs focused on a single issue
- Very specific: line 194
Ensure tests pass (npx gulp test)
- Distinctive: line 196
Follow existing code patterns
- Distinctive: line 197
Don't modify translations directly (they come from Firefox)
≈ “Common” is an estimate: at least 1 in 5 of the 36,368 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Overview
PDF.js is a Portable Document Format (PDF) viewer built with JavaScript, HTML5 Canvas, and CSS. It's a Mozilla project that provides a general-purpose, web standards-based platform for parsing and rendering PDFs without requiring native code or plugins.
Common Commands
Development Server
npx gulp serverThen open http://localhost:8888/web/viewer.html to view the PDF viewer. Test PDFs are available at http://localhost:8888/test/pdfs/?frame
Building
Build for modern browsers:
npx gulp genericThis generates pdf.js and pdf.worker.js in build/generic/build/.
Build for distribution (creates pdfjs-dist package):
npx gulp dist
npx gulp dist-install # Build and install locallyTesting
Run all tests:
npx gulp testRun unit tests only:
npx gulp unittestRun integration tests (browser-based tests using Puppeteer):
npx gulp integrationtestRun font tests:
npx gulp fonttestRun a single test file by modifying test/test_manifest.json or using test runner options.
Linting and Formatting
Lint JavaScript:
npx gulp lintFormat code (uses Prettier and ESLint):
npx eslint --fix <file>Type Checking
Run TypeScript type checking:
npx gulp typestestArchitecture
High-Level Structure
PDF.js has a multi-layer architecture that separates concerns between PDF parsing, rendering, and UI:
1. Core Layer (src/core/)
The core layer handles PDF parsing and interpretation. Key responsibilities:
- PDF parsing: Parsing PDF structure, cross-reference tables, streams
- Font handling: CFF, TrueType, Type1 font parsing and conversion (
font.js,fonts.js,cff_*.js,type1_*.js) - Image decoding: JPEG, JBIG2, JPX/JPEG2000 decoders
- Operators: Processing PDF drawing operators (
operator_list.js,evaluator.js) - XFA Forms: XML Forms Architecture support (
src/core/xfa/) - Color spaces: ICC profiles, device color spaces (
colorspace.js,icc_colorspace.js) - Runs in a Web Worker for performance isolation
Entry point: src/pdf.worker.js
2. Display Layer (src/display/)
The display layer provides the API for rendering PDFs to canvas and managing documents. Key components:
- API: Main public API (
api.js) -PDFDocumentProxy,PDFPageProxy,getDocument() - Canvas rendering: Renders PDF operations to HTML5 canvas (
canvas.js) - Text layer: Extracts and positions text for selection/search (
text_layer.js) - Annotation layer: Renders and handles PDF annotations (
annotation_layer.js) - Editor layer: Supports PDF editing (annotations, highlights, stamps) (
editor/) - Metadata: Parses XMP metadata (
metadata.js) - Streams: Handles PDF data fetching (fetch, network, node) (
fetch_stream.js,network.js,node_stream.js)
Entry point: src/pdf.js
3. Scripting Layer (src/scripting_api/)
Implements JavaScript execution for interactive PDFs (form calculations, validations, button actions).
- Sandboxed execution environment
- Implements Acrobat JavaScript API objects (App, Doc, Field, etc.)
Entry points: src/pdf.scripting.js, src/pdf.sandbox.js
4. Web Viewer (web/)
The complete PDF viewer application with UI. Key components:
- Main app: Application orchestration (
app.js) - Viewer: Page rendering and layout (
pdf_viewer.js,pdf_page_view.js) - Toolbar: Zoom, page navigation, print, download controls
- Sidebar: Thumbnails, outlines, attachments (
pdf_sidebar.js,pdf_thumbnail_view.js,pdf_outline_viewer.js) - Find controller: Text search functionality (
pdf_find_controller.js) - Annotation editors: UI for creating/editing annotations (
annotation_editor_layer_builder.js) - Presentation mode: Full-screen presentation (
pdf_presentation_mode.js)
Entry point: web/viewer.html + web/viewer.mjs
5. Shared Utilities (src/shared/)
Common utilities used across layers:
- Message handling: Worker communication (
message_handler.js) - Utilities: Common functions and constants (
util.js) - Image utilities: Image processing helpers (
image_utils.js)
Worker Communication
PDF.js uses a Web Worker architecture:
- Main thread (
displaylayer) communicates with worker thread (corelayer) viaMessageHandler - Keeps PDF parsing off the main thread for better performance
- Messages include: page rendering requests, text content extraction, metadata queries
Build System
- Uses Gulp for build orchestration (
gulpfile.mjs) - Webpack bundles modules into browser-compatible formats
- Babel transpiles for browser compatibility (configurable targets in gulpfile)
- Preprocessor replaces build-time constants (e.g.,
typeof PDFJSDev !== "undefined"checks) - Multiple build targets: generic, components, minified, legacy (older browser support)
External Dependencies
Located in external/:
- bcmaps: Binary CMaps for CJK fonts
- standard_fonts: Core 14 PDF fonts metrics
- cmapscompress: Tools for compressing CMaps
- openjpeg: JPEG2000 decoder (WASM)
- quickjs: JavaScript engine for sandboxed execution
Translations
Translations in l10n/ are imported from Mozilla Firefox Nightly. Only the file l10n/en-US/viewer.ftl can be updated.
Development Notes
Adding New Features
When adding features that span multiple layers:
- Start with the
corelayer if parsing/interpretation changes are needed - Update the
displaylayer API if new capabilities need exposure - Modify the
webviewer if UI changes are required - Ensure worker communication handles new message types
Preprocessor Directives
Code uses preprocessor checks for build-time conditionals:
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC")) {
// Generic build-specific code
}Common flags: GENERIC, MOZCENTRAL, CHROME, MINIFIED, TESTING, LIB, SKIP_BABEL, IMAGE_DECODERS
Testing
- Unit tests use Jasmine framework (
test/unit/) - Integration tests use Puppeteer for browser automation (
test/integration/) - Test PDFs downloaded from manifest (
test/test_manifest.json) - Reference images for visual regression testing (
test/ref/)
Code Style
- Uses ESLint with custom configuration (
eslint.config.mjs) - Prettier for formatting
- Stylelint for CSS
- No semicolons required (ASI enabled)
- Single quotes for strings
Pull Request Process
- Keep PRs focused on a single issue
- Provide a test PDF if the issue is PDF-specific
- Ensure tests pass (
npx gulp test) - Run linting (
npx gulp lint) - Follow existing code patterns
- Don't modify translations directly (they come from Firefox)
Performance Considerations
- Core parsing runs in a Web Worker - keep main thread work minimal
- Canvas rendering can be expensive - use appropriate scale factors
- Text layer generation is separate from rendering - can be deferred
- Annotation layer is optional - only enable when needed
Trending
Steady talk.about the whole repository
Who's talking about mozilla/pdf.js
- Snyk“Why You Should be AFRAID of PDF Files - PDF.js CVE-2024-4367”YouTube · Jun 10, 2024 · 10k views
- SemperVideo“Firefox 19 unterstützt PDF”YouTube · Feb 23, 2013 · 10k views
- Archived Yu-Jie Lin“Mozilla PDF.js viewer (builtin Firefox 19+)”YouTube · Jan 13, 2014 · 5.8k views
- CodeLie“Como carregar e mostrar arquivo PDF com Javascript”YouTube · Apr 11, 2020 · 5.6k views
- Lập Trình Cho Website“Hướng Dẫn Sử Dụng Thư viện PDFJS Để Đọc File PDF”YouTube · Dec 25, 2021 · 1.6k views
The biggest 5 of 76 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 76
Talked about on Stack Overflow, GitHub, YouTube, Hacker News, Bluesky and the web (76 times).
On Stack Overflow · 30
- Nov 15, 2008Recommended way to embed PDF in HTML?611 votes
- Jan 18, 2021Create react app - how to copy pdf.worker.js file from pdfjs-dist/build to your project's output folder?37 votes
- Nov 16, 2016What is a pdf bcmap file?33 votes
- Feb 17, 2012How to Use pdf.js33 votes
- Mar 29, 2017How to open local PDF file in WebView in Android?30 votes
25 more on Stack Overflow
- Oct 11, 2015pdf.js with text selection27 votes · 3 answers
- Jan 4, 2015Chrome extension: How to show custom UI for a PDF file?24 votes
- Oct 15, 2015pdf.js with text selection20 votes
- Dec 22, 2014Zoom on simple pdf.js viewer19 votes · 3 answers
- Nov 22, 2013Links, Hyperlinks into a canvas using PDF.js19 votes
- Aug 6, 2020How to use annotation layer in PDF.js?18 votes · 2 answers
- Dec 15, 2016How to display whole PDF (not only one page) with PDF.JS?16 votes
- Jan 31, 2013Inline PDF viewer16 votes
- Mar 29, 2017Open PDF in a WebView15 votes
- Oct 3, 2020Reading pdf from url with node.js using PDF.js14 votes
- Jan 11, 2017viewer.js / pdf.js: Memory usage increases every time a pdf is rendered14 votes
- Sep 27, 2016How to highlight text with PDFJS?14 votes · 1 answer
- May 12, 2014How to make PDF undownloadable using pdf.js14 votes
- Apr 26, 2013Print PDF directly from JavaScript13 votes
- Jun 17, 2021Create react app - how to copy pdf.worker.js file from pdfjs-dist/build to your project's output folder?12 votes
- Jun 13, 2017Using pdf.js on a node server12 votes · 1 answer
- Jun 15, 2021PDF.js scale PDF on fixed width11 votes
- Apr 21, 2016No PDFJS.workerSrc specified11 votes
- Aug 19, 2015PDF.js - Using search function on embedded PDF11 votes
- May 20, 2020I have an error with PDF.JS with the global worker and the async10 votes · 3 answers
- Mar 6, 2012PDF Rendering in HTML5 Canvas9 votes · 1 answer
- Aug 16, 2016z-index does not work in Internet Explorer with pdf in iframe8 votes
- Oct 23, 2020How to add UI and toolbar to PDF.js viewer?7 votes
- Apr 4, 2019React How to Print a PDF File Within a Component View7 votes
- Sep 4, 2013How to get height of PDF document load in iframe7 votes
On GitHub · 28
- Mar 31, 2026Update pdfjs version to v6.0.227 — wojtekmaj/react-pdf25 reactions · 3 comments
- Jan 13, 2023pdfjs black flicker — wojtekmaj/react-pdf19 reactions · 4 comments
- Mar 15, 2025Support the latest PDF.js version — wojtekmaj/react-pdf15 reactions · 1 comment
- Dec 20, 2023Upgrade pdfjs to expose PDF.js highlighting editor — nextcloud/files_pdfviewer14 reactions · 4 comments
- Feb 13, 2019Dependencies that use require.ensure for backward compatibility cause warnings — react/create-react-app14 reactions · 12 comments
23 more on GitHub
- Aug 4, 2022PDF.js "... is not a function" error — qutebrowser/qutebrowser11 reactions · 8 comments
- Jun 29, 2024pdfjs crashes on getDocument if worker is set using pdfjs.GlobalWorkerOptions.workerPort and second file is rendered — wojtekmaj/react-pdf10 reactions · 9 comments
- Nov 30, 2020Segmentation Fault — Automattic/node-canvas10 reactions · 1 comment
- Jun 3, 2020Release 2.0.0 broken - can't resolve 'worker-loader' in '/opt/conda/share/jupyter/lab/staging/node_modules/pdfjs-dist' — jupyterlab/jupyterlab-latex10 reactions · 13 comments
- Jan 25, 2021Feature request: update to latest pdf.js v2.7.570 — VadimDez/ng2-pdf-viewer9 reactions · 10 comments
- Jan 4, 2024[breaking] Update pdfjs-dist to 4.0.379 — wojtekmaj/react-pdf7 reactions · 2 comments
- Jul 21, 2021Disable embedded print script — stephanrauh/ngx-extended-pdf-viewer7 reactions · 8 comments
- Jul 7, 2021pdfjs-dist has changed directory structure - a breaking change — ol-th/pdf-img-convert.js7 reactions
- Feb 10, 2025Error: Cannot find module '@napi-rs/canvas' — telerik/kendo-react6 reactions · 3 comments
- Jan 13, 2025feat(pageColor): add option to invert pdf pageColor — mathematic-inc/vscode-pdf4 reactions · 1 comment
- May 4, 2020simplify code contributions + reviews by fully automating the dev setup. — treeverse/dvc.org4 reactions · 18 comments
- Mar 17, 2023fix(pdf): incorrect filename encoding — logseq/logseq3 reactions · 4 comments
- Nov 18, 2020fix text selection flickering and chrome performance — wojtekmaj/react-pdf3 reactions · 1 comment
- Mar 16, 2018New canvas on each render — FranckFreiburger/vue-pdf3 reactions · 7 comments
- Jul 28, 2026fix(pdf): update match counter during navigation — stablyai/orca2 reactions · 4 comments
- Jul 13, 2026chore(deps): bump pdfjs-dist from 4.10.38 to 6.1.200 — darkmaster0345/Noor-connect2 reactions · 6 comments
- May 19, 2026Bump the npm_and_yarn group across 4 directories with 12 updates — CakekritsananXi/Flowise2 reactions · 1 comment
- May 14, 2026Bump the npm_and_yarn group across 3 directories with 7 updates — HarleyCoops/Flowise2 reactions · 3 comments
- Apr 1, 2026chore(deps): bump pdfjs-dist from 3.11.174 to 4.2.67 — cicero-im/magic-web2 reactions · 1 comment
- Apr 1, 2026build(deps): bump pdfjs-dist from 3.11.174 to 4.2.67 in /frontend/magic-web — cicero-im/magic2 reactions · 1 comment
- Jan 20, 2026Bump the npm_and_yarn group across 9 directories with 9 updates — patrik-fredon/platform2 reactions · 1 comment
- Jun 2, 2024Use DCTDecode and SMask when saving LA and RGBA PDF images — python-pillow/Pillow2 reactions · 4 comments
- Nov 12, 2022Support for pdf links with named destinations — tomoki1207/vscode-pdfviewer2 reactions · 2 comments
On YouTube · 9
- Jun 10, 2024Why You Should be AFRAID of PDF Files - PDF.js CVE-2024-4367 — Snyk10k views · 15 comments
- Feb 23, 2013Firefox 19 unterstützt PDF — SemperVideo10k views · 70 comments
- Jan 13, 2014Mozilla PDF.js viewer (builtin Firefox 19+) — Archived Yu-Jie Lin5.8k views · 3 comments
- Apr 11, 2020Como carregar e mostrar arquivo PDF com Javascript — CodeLie5.6k views · 4 comments
- Dec 25, 2021Hướng Dẫn Sử Dụng Thư viện PDFJS Để Đọc File PDF — Lập Trình Cho Website1.6k views
4 more on YouTube
- Oct 20, 2013mozilla - pdf.js — GourceTV1.5k views · 1 comment
- May 2, 2024Solving Web to PDF Printing Challenges with Elixir | S12E07 Elixir Wizards Podcast by SmartLogic — SmartLogic146 views
- May 2, 2024"Printing is Ugly" with Joel Meador and Charles Suggs — SmartLogic19 views
- Mar 1, 2026Koi™ Assistant: private data on private server — Dan Tian14 views
On Hacker News · 4
- Feb 10, 2013Pdf.js - PDF Reader in JavaScript3 points
- Oct 30, 2026PDF Reader in JavaScript2 points
- Aug 15, 2024Pdf.js: A Lightweight, Native PDF Reader Built in JavaScript2 points
- Mar 3, 2017Tell HN: Mozilla's pdf.js needs help with automated testing (2016)says it tested it1 point
On Bluesky · 3
- Feb 19, 2026What is a good general PDF viewer to embed on websites? What I want is a consistent view across browsers. I keep finding this one. Any… — @leopold.is3 likes and reposts · 1 reply
- Apr 3, 2024📦 mozilla / pdf.js ⭐ 45,946 (+31) 🗒 JavaScript PDF Reader in JavaScript — @github-trending-js.bsky.social1 likes and repost
- Jan 23, 2024📦 mozilla / pdf.js ⭐ 45,164 (+51) 🗒 JavaScript PDF Reader in JavaScript — @github-trending-js.bsky.social1 likes and repost
On the web · 2
- Oct 4, 2026PDF.js download — google.com
- Jul 30, 2021How to use and extend Mozilla's PDF.js Viewer — google.com
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 28,693 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

