

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
1## Overview23PDF.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.45## Common Commands67### Development Server8```bash9npx gulp server10```11Then open http://localhost:8888/web/viewer.html to view the PDF viewer. Test PDFs are available at http://localhost:8888/test/pdfs/?frame1213### Building1415Build for modern browsers:16```bash17npx gulp generic18```1920This generates `pdf.js` and `pdf.worker.js` in `build/generic/build/`.2122Build for distribution (creates pdfjs-dist package):23```bash24npx gulp dist25npx gulp dist-install # Build and install locally26```2728### Testing2930Run all tests:31```bash32npx gulp test33```3435Run unit tests only:36```bash37npx gulp unittest38```3940Run integration tests (browser-based tests using Puppeteer):41```bash42npx gulp integrationtest43```4445Run font tests:46```bash47npx gulp fonttest48```4950Run a single test file by modifying test/test_manifest.json or using test runner options.5152### Linting and Formatting5354Lint JavaScript:55```bash56npx gulp lint57```5859Format code (uses Prettier and ESLint):60```bash61npx eslint --fix <file>62```6364### Type Checking6566Run TypeScript type checking:67```bash68npx gulp typestest69```7071## Architecture7273### High-Level Structure7475PDF.js has a multi-layer architecture that separates concerns between PDF parsing, rendering, and UI:7677#### 1. Core Layer (`src/core/`)78The core layer handles PDF parsing and interpretation. Key responsibilities:79- **PDF parsing**: Parsing PDF structure, cross-reference tables, streams80- **Font handling**: CFF, TrueType, Type1 font parsing and conversion (`font.js`, `fonts.js`, `cff_*.js`, `type1_*.js`)81- **Image decoding**: JPEG, JBIG2, JPX/JPEG2000 decoders82- **Operators**: Processing PDF drawing operators (`operator_list.js`, `evaluator.js`)83- **XFA Forms**: XML Forms Architecture support (`src/core/xfa/`)84- **Color spaces**: ICC profiles, device color spaces (`colorspace.js`, `icc_colorspace.js`)85- Runs in a Web Worker for performance isolation8687Entry point: `src/pdf.worker.js`8889#### 2. Display Layer (`src/display/`)90The display layer provides the API for rendering PDFs to canvas and managing documents. Key components:91- **API**: Main public API (`api.js`) - `PDFDocumentProxy`, `PDFPageProxy`, `getDocument()`92- **Canvas rendering**: Renders PDF operations to HTML5 canvas (`canvas.js`)93- **Text layer**: Extracts and positions text for selection/search (`text_layer.js`)94- **Annotation layer**: Renders and handles PDF annotations (`annotation_layer.js`)95- **Editor layer**: Supports PDF editing (annotations, highlights, stamps) (`editor/`)96- **Metadata**: Parses XMP metadata (`metadata.js`)97- **Streams**: Handles PDF data fetching (fetch, network, node) (`fetch_stream.js`, `network.js`, `node_stream.js`)9899Entry point: `src/pdf.js`100101#### 3. Scripting Layer (`src/scripting_api/`)102Implements JavaScript execution for interactive PDFs (form calculations, validations, button actions).103- Sandboxed execution environment104- Implements Acrobat JavaScript API objects (App, Doc, Field, etc.)105106Entry points: `src/pdf.scripting.js`, `src/pdf.sandbox.js`107108#### 4. Web Viewer (`web/`)109The complete PDF viewer application with UI. Key components:110- **Main app**: Application orchestration (`app.js`)111- **Viewer**: Page rendering and layout (`pdf_viewer.js`, `pdf_page_view.js`)112- **Toolbar**: Zoom, page navigation, print, download controls113- **Sidebar**: Thumbnails, outlines, attachments (`pdf_sidebar.js`, `pdf_thumbnail_view.js`, `pdf_outline_viewer.js`)114- **Find controller**: Text search functionality (`pdf_find_controller.js`)115- **Annotation editors**: UI for creating/editing annotations (`annotation_editor_layer_builder.js`)116- **Presentation mode**: Full-screen presentation (`pdf_presentation_mode.js`)117118Entry point: `web/viewer.html` + `web/viewer.mjs`119120#### 5. Shared Utilities (`src/shared/`)121Common utilities used across layers:122- **Message handling**: Worker communication (`message_handler.js`)123- **Utilities**: Common functions and constants (`util.js`)124- **Image utilities**: Image processing helpers (`image_utils.js`)125126### Worker Communication127128PDF.js uses a Web Worker architecture:129- Main thread (`display` layer) communicates with worker thread (`core` layer) via `MessageHandler`130- Keeps PDF parsing off the main thread for better performance131- Messages include: page rendering requests, text content extraction, metadata queries132133### Build System134135- Uses **Gulp** for build orchestration (`gulpfile.mjs`)136- **Webpack** bundles modules into browser-compatible formats137- **Babel** transpiles for browser compatibility (configurable targets in gulpfile)138- Preprocessor replaces build-time constants (e.g., `typeof PDFJSDev !== "undefined"` checks)139- Multiple build targets: generic, components, minified, legacy (older browser support)140141### External Dependencies142143Located in `external/`:144- **bcmaps**: Binary CMaps for CJK fonts145- **standard_fonts**: Core 14 PDF fonts metrics146- **cmapscompress**: Tools for compressing CMaps147- **openjpeg**: JPEG2000 decoder (WASM)148- **quickjs**: JavaScript engine for sandboxed execution149150### Translations151152Translations in `l10n/` are imported from Mozilla Firefox Nightly. Only the file l10n/en-US/viewer.ftl can be updated.153154## Development Notes155156### Adding New Features157158When adding features that span multiple layers:1591. Start with the `core` layer if parsing/interpretation changes are needed1602. Update the `display` layer API if new capabilities need exposure1613. Modify the `web` viewer if UI changes are required1624. Ensure worker communication handles new message types163164### Preprocessor Directives165166Code uses preprocessor checks for build-time conditionals:167```javascript168if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC")) {169 // Generic build-specific code170}171```172173Common flags: `GENERIC`, `MOZCENTRAL`, `CHROME`, `MINIFIED`, `TESTING`, `LIB`, `SKIP_BABEL`, `IMAGE_DECODERS`174175### Testing176177- Unit tests use Jasmine framework (`test/unit/`)178- Integration tests use Puppeteer for browser automation (`test/integration/`)179- Test PDFs downloaded from manifest (`test/test_manifest.json`)180- Reference images for visual regression testing (`test/ref/`)181182### Code Style183184- Uses ESLint with custom configuration (`eslint.config.mjs`)185- Prettier for formatting186- Stylelint for CSS187- No semicolons required (ASI enabled)188- Single quotes for strings189190### Pull Request Process191192- Keep PRs focused on a single issue193- Provide a test PDF if the issue is PDF-specific194- Ensure tests pass (`npx gulp test`)195- Run linting (`npx gulp lint`)196- Follow existing code patterns197- Don't modify translations directly (they come from Firefox)198199### Performance Considerations200201- Core parsing runs in a Web Worker - keep main thread work minimal202- Canvas rendering can be expensive - use appropriate scale factors203- Text layer generation is separate from rendering - can be deferred204- Annotation layer is optional - only enable when needed205
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 201k | AGENTS.md | buildteststylearch+3 | 100/100 | 14 days ago | |
| aaif-goose/gooseAGENTS.md · 53k | AGENTS.md | setupbuildtestlint-format+7 | 100/100 | 8 days ago | |
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 14 days ago | |
| deepseek-ai/deepseek-harnessnative/landlock-run/AGENTS.md · 104k | AGENTS.md | setupteststylearch+3 | 100/100 | today | |
| code-yeongyu/oh-my-openagentpackages/web/AGENTS.md · 68k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 13 days ago | |
| TryGhost/Ghoste2e/AGENTS.md · 55k | AGENTS.md | setupteststylearch+2 | 100/100 | today | |
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 14 days ago | |
| elastic/elasticsearchx-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/AGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+2 | 100/100 | 14 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/mozilla-pdf-js-agents)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.