agentleFS
mozillamozilla/pdf.js/AGENTS.md

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
  1. Distinctive:

    Run unit tests only:

    line 35
  2. Distinctive:

    Run integration tests (browser-based tests using Puppeteer):

    line 40
  3. Very specific:

    Run a single test file by modifying test/test_manifest.json or using test runner options.

    line 50
  4. Distinctive:

    Run TypeScript type checking:

    line 66
  5. Distinctive:

    When adding features that span multiple layers:

    line 158
  6. Very specific:

    Start with the core layer if parsing/interpretation changes are needed

    line 159
  7. Very specific:

    Update the display layer API if new capabilities need exposure

    line 160
  8. Distinctive:

    Ensure worker communication handles new message types

    line 162
  9. Very specific:

    Test PDFs downloaded from manifest (test/test_manifest.json)

    line 179
  10. Distinctive:

    No semicolons required (ASI enabled)

    line 187
  11. Distinctive:

    Keep PRs focused on a single issue

    line 192
  12. Very specific:

    Ensure tests pass (npx gulp test)

    line 194
  13. Distinctive:

    Follow existing code patterns

    line 196
  14. Distinctive:

    Don't modify translations directly (they come from Firefox)

    line 197

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

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 server

Then 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 generic

This 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 locally

Testing

Run all tests:

npx gulp test

Run unit tests only:

npx gulp unittest

Run integration tests (browser-based tests using Puppeteer):

npx gulp integrationtest

Run font tests:

npx gulp fonttest

Run a single test file by modifying test/test_manifest.json or using test runner options.

Linting and Formatting

Lint JavaScript:

npx gulp lint

Format code (uses Prettier and ESLint):

npx eslint --fix <file>

Type Checking

Run TypeScript type checking:

npx gulp typestest

Architecture

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 (display layer) communicates with worker thread (core layer) via MessageHandler
  • 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:

  1. Start with the core layer if parsing/interpretation changes are needed
  2. Update the display layer API if new capabilities need exposure
  3. Modify the web viewer if UI changes are required
  4. 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

Download now (ZIP)

Trending

Steady talk.about the whole repository

Dec 2025: 0 mentionsJan 2026: 1 mentionFeb 2026: 1 mentionMar 2026: 2 mentionsApr 2026: 2 mentionsMay 2026: 2 mentionsJun 2026: 0 mentionsJul 2026: 2 mentionsAug 2026: 0 mentionsSep 2026: 0 mentionsOct 2026: 2 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the mozilla/pdf.js repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about mozilla/pdf.js

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

25 more on Stack Overflow

On GitHub · 28

23 more on GitHub

On YouTube · 9

4 more on YouTube

On Bluesky · 3

On the web · 2

  • 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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.