Notes on streaming PDFs
Engineering deep-dives, specification notes, and performance lessons from building the fastest online PDF reader.
Edit
Convert
Security
Engineering deep-dives, specification notes, and performance lessons from building the fastest online PDF reader.
Articles tagged “Internals”
A guided tour of PDF.js internals, from architecture to rendering.

How PDF.js loads documents and fetches pages: the Display layer entry points getDocument and getPage.
October 19, 2026 · StreamPDF Team

Tracing the Display layer methods getViewport and render in PDF.js: how page viewports are computed and how a page is rendered through the main ↔ worker rendering pipeline.
October 22, 2026 · StreamPDF Team

How PDF.js wires all main-worker communication: send, sendWithPromise, and sendWithStream with backpressure.
October 22, 2026 · StreamPDF Team

A source-level tour of PDF.js PDFFetchStream: when fetch resolves, when the full stream gets cancelled, how Range requests cross the worker and main thread, and why Content-Encoding must be identity.
October 25, 2026 · StreamPDF Team

PDF.js PDFManager.initDocument source code walkthrough.
October 25, 2026 · StreamPDF Team
Start from demo code and follow the call chain deep into PDF.js.

Starting from a minimal custom viewer demo, follow the complete call chain from getDocument and getPage to getViewport and render, deep into the rendering principles of the PDF.js display layer.
October 19, 2026 · StreamPDF Team

Follow the demo through the complete getDocument call: loading task creation, 35+ parameter parsing, worker creation and the GetDocRequest handshake, all the way to the synchronous return of loadingTask.
October 27, 2026 · StreamPDF Team

Follow the demo through the complete getPage call: page number validation, page number mapping, three layers of caching, the GetPage message, and the creation of PDFPageProxy.
October 27, 2026 · StreamPDF Team

Follow the demo through the full computation of getViewport: page viewBox and userUnit, the rotation vector, the y-axis flip, and the step-by-step derivation of the transform matrix.
October 27, 2026 · StreamPDF Team

Follow the demo through the complete render call: rendering intent bit operations, streaming operator list fetching, the creation and startup of InternalRenderTask, and the await pitfall.
October 27, 2026 · StreamPDF Team

Follow three concrete calls in the demo — Ready, GetPage, and GetOperatorList — to dive deep into MessageHandler's envelope protocol, three message shapes, and ReadableStream bidirectional backpressure.
October 27, 2026 · StreamPDF Team

Follow the demo through WorkerTransport initialization: six constructor arguments, message handler registration, Ready-triggered loading, the GetReader data channel, and how GetDoc resolves loadingTask.promise.
October 27, 2026 · StreamPDF Team

Return to the demo's PDFWorker.create call and follow workerSrc, the CDN Blob wrapper, the two-way ready/test handshake, worker.promise readiness, and the LoopbackPort fake-worker fallback.
October 27, 2026 · StreamPDF Team

Follow the demo's real response headers through range capability detection, 344 64KB chunks, NetworkPdfManager retries for missing chunks, and the point where GetRangeReader meets the progressive full stream.
October 27, 2026 · StreamPDF Team

Follow the 84 real operators from the demo first page through CanvasGraphics initialization, numeric opcode dispatch, font dependency pauses, 15ms time slices, and rendering completion with lastChunk.
October 27, 2026 · StreamPDF Team

Follow the 83 operators inside the demo first page 1293-byte content stream through GetOperatorList on the worker: 82 direct operators, 2 injected dependencies, and the real rules behind Tf, TJ, BDC, and gs.
October 27, 2026 · StreamPDF Team

Follow the demo's two embedded Type1C fonts through PDF.js's font pipeline: loadFont caching and hash deduplication, the preEvaluateFont fingerprint, repacking CFF as OpenType, compileFontInfo binary serialization, commonobj transfer, and mounting via FontFace on the main thread.
October 28, 2026 · StreamPDF Team

Step into the worker thread: follow the demo through GetDocRequest handling — version check, prototype-pollution guard, the d0_worker document channel and 20+ message registrations — then through setupDoc after Ready: PdfManager selection, the five steps of initDocument, and the GetDoc reply.
October 29, 2026 · StreamPDF Team
A file-by-file walkthrough of the PDF.js source tree.

PDF.js PartialEvaluator source code walkthrough.
October 25, 2026 · StreamPDF Team

A source code walkthrough of the PDF.js PDFDocument and Page classes.
October 26, 2026 · StreamPDF Team

PDF.js CanvasGraphics source code walkthrough.
October 26, 2026 · StreamPDF Team

PDF.js XRef source walkthrough: cross-reference tables, xref streams, object streams, and how objects are located and retrieved.
October 26, 2026 · StreamPDF Team

A source code walkthrough of the PDF.js Lexer and Parser: tokenize byte by byte, then assemble tokens into PDF objects by recursive descent.
October 26, 2026 · StreamPDF Team

PDF.js BaseStream source walkthrough: the byte-stream abstraction contract, lookahead and multi-byte reads, cursor control, derived streams and async decoding capabilities.
October 27, 2026 · StreamPDF Team

PDF.js Stream source walkthrough: the start/pos/end triple of pointers, zero-copy subarray views, substreams and clones, plus the StringStream and NullStream subclasses.
October 27, 2026 · StreamPDF Team

PDF.js ChunkedStream and ChunkedStreamManager source walkthrough: chunked buffering, Range request merging, retry on missing data, and streaming prefetch.
October 27, 2026 · StreamPDF Team

PDF.js DecodeStream source walkthrough: output buffer growth, lazy reading, asynchronous image decoding, and the shared base for stitching multiple streams together.
October 27, 2026 · StreamPDF Team

PDF.js FlateStream source walkthrough: zlib header validation, bit buffering, Huffman table generation, the three DEFLATE block types and LZ77 back-references.
October 27, 2026 · StreamPDF Team

PDF.js PredictorStream source walkthrough: TIFF and PNG row predictors, the five filter formulas, row-buffer reuse and truncation handling.
October 27, 2026 · StreamPDF Team

PDF.js LZWStream source walkthrough: 9-bit variable-length codes, a three-array dictionary, the earlyChange widening point, and the KwKwK special case.
October 27, 2026 · StreamPDF Team

PDF.js Ascii85Stream source walkthrough: five-character groups, the z shortcut for zero groups, whitespace skipping, and padding for a short final group.
October 27, 2026 · StreamPDF Team

PDF.js AsciiHexStream source walkthrough: bitwise decoding of hexadecimal text into bytes, nibble state across block boundaries, and end-marker handling.
October 27, 2026 · StreamPDF Team

PDF.js RunLengthStream source walkthrough: the two run semantics of the header byte, bulk fills, and buffer accumulation across blocks.
October 27, 2026 · StreamPDF Team

PDF.js BrotliStream source walkthrough: an async fast path over the browser DecompressionStream first, falling back to the bundled external/brotli decoder on whole-buffer failure.
October 27, 2026 · StreamPDF Team

PDF.js DecryptStream source walkthrough: 512-byte chunks, a lookahead that detects the last chunk, the final flag, and stream identity at the decryption layer.
October 27, 2026 · StreamPDF Team

PDF.js JpegStream source walkthrough: how DCTDecode restores JPEG pixels through both JpegImage and the browser ImageDecoder path.
October 27, 2026 · StreamPDF Team

PDF.js Jbig2Stream source walkthrough: JBIG2Decode file-header stripping, global-segment merging, and the asynchronous WASM decoding chain.
October 27, 2026 · StreamPDF Team

PDF.js JpxStream source walkthrough: whole-image JPEG 2000 decoding, lazy byte reads, and the bridge to an asynchronous WASM decoder.
October 27, 2026 · StreamPDF Team

PDF.js CCITTFaxStream source walkthrough: normalizing fax-encoding parameters, the K-value group semantics, and delegation to a WASM decoder.
October 27, 2026 · StreamPDF Team

PDF.js worker byte-stream adapter source walkthrough: how PDFWorkerStream carries display-layer network chunks into the Worker through the message protocol.
October 27, 2026 · StreamPDF Team

PDF.js primitives source walkthrough: interning Name and Cmd, dereferencing and merging Dict, caching Ref strings, and the reference sets RefSet and RefMap.
October 27, 2026 · StreamPDF Team

PDF.js core_utils source walkthrough: the shared toolbox of exception families, inheritance chains, escaping, action collection and XML encoding.
October 27, 2026 · StreamPDF Team

A walkthrough of PDF.js crypto.js: the standard security handler, RC4 and AES cipher implementations, password validation, object key derivation, and the streaming decryption dispatch chain.
October 27, 2026 · StreamPDF Team

PDF.js obj_bin_transform_core source walkthrough: compiling fonts, system fonts, patterns and glyph paths into transferable binary data for the worker boundary.
October 27, 2026 · StreamPDF Team

PDF.js object_loader source walkthrough: how ObjectLoader walks an object graph iteratively and batches every missing byte range into one request.
October 27, 2026 · StreamPDF Team

PDF.js pdf_manager source walkthrough: how BasePdfManager unifies document data access across an in-memory byte array and chunked network downloads.
October 27, 2026 · StreamPDF Team

How the PDF.js Catalog turns the /Root dictionary into a document model of page trees, name trees, outlines, attachments and forms.
October 27, 2026 · StreamPDF Team

PDF.js struct_tree source walkthrough: StructTreeRoot, ParentTree, per-page structure tree serialization, and the accessibility contract shared with the main thread.
October 27, 2026 · StreamPDF Team

A PDF.js walkthrough of the NameTree and NumberTree implementation: node traversal, Limits binary search, lazy dereferencing, and cycle protection.
October 27, 2026 · StreamPDF Team

A PDF.js walkthrough of XMP metadata parsing: repairing malformed text, the SimpleXMLParser state machine, rdf:Description traversal, and the flattened Map result.
October 27, 2026 · StreamPDF Team

A PDF.js walkthrough of default appearance handling: parsing font size and color operators from the /DA string, evaluating appearance streams, and generating a FakeUnicodeFont.
October 27, 2026 · StreamPDF Team

Shared utilities of the PDF.js font layer: FontFlags, the standard Mac glyph order, glyph-name recovery, Type1 character mapping, font-name normalisation, vertical presentation forms and Type3 bitmap compilation.
October 27, 2026 · StreamPDF Team

The standard font data layer of PDF.js: the standard 14 font aliases, substitute font mappings, the serif and symbol name sets, and the CID to glyph maps used when a font has no embedded file.
October 27, 2026 · StreamPDF Team

The core 14 font metric tables of the PDF.js font layer: where glyph widths, ascent and descent come from, and how they meet the fontMatrix conversion at 1/1000 em.
October 27, 2026 · StreamPDF Team

The single-byte encoding surface of PDF.js: seven 256-entry encoding tables, the char code to glyph name mapping, and how getEncoding divides work with CMap and ToUnicode.
October 27, 2026 · StreamPDF Team

How the PDF.js CMap translates character codes into CIDs or Unicode: codespaces, bf/cid ranges, useCMap chains and the built-in mapping factory.
October 27, 2026 · StreamPDF Team

How the PDF.js BinaryCMapReader uses big-endian bytes, varints and delta encoding to decode the codespaces and bf/cid mappings of built-in CMaps.
October 27, 2026 · StreamPDF Team

PDF.js glyphlist turns glyph names into Unicode through two lazily built tables, and explains who covers the gap when a lookup fails.
October 27, 2026 · StreamPDF Team

The core of the PDF.js font layer: how Font dispatches by type, repairs TrueType, wraps Type1/CFF, and builds ToUnicode plus the glyph caches.
October 27, 2026 · StreamPDF Team

A source walkthrough of api.js, the display-layer entry point of PDF.js: getDocument's one-shot parameter expansion, PDFWorker's test handshake and fake-worker fallback, WorkerTransport's message routing table, PDFPageProxy's intentState state machine, and RenderTask's scheduling loop.
October 27, 2026 · StreamPDF Team

A source walkthrough of MessageHandler, PDF.js cross-thread message hub: three message shapes (fire-and-forget / request-reply / streaming), the three-layer envelope protocol, and the StreamKind state machine with bidirectional backpressure built on ReadableStream.
October 27, 2026 · StreamPDF Team

A source walkthrough of PDF.js shared utilities: specification constants, typed exceptions, URL validation, binary strings, cached feature detection, affine geometry, destination validation, and runtime compatibility shims.
October 27, 2026 · StreamPDF Team

A source-level walkthrough of BasePDFStream: the single full reader, conditional range readers, headersReady metadata, abstract read/cancel contracts, cancellation semantics, and how fetch, XHR, Node.js, and push transports fulfill them.
October 27, 2026 · StreamPDF Team

A source-level walkthrough of PDF.js image_utils.js: ImageKind dispatch, 1-bit mask expansion, packed RGB-to-RGBA conversion, grayscale replication, endian-aware Uint32 writes, and the real canvas and decoder call sites.
October 27, 2026 · StreamPDF Team

PDF.js obj_bin_transform_utils source walkthrough: the shared field-order and byte-offset schema for font and pattern buffers, plus the lazy UTF-8 codecs used by the worker writer and main-thread reader.
October 27, 2026 · StreamPDF Team

PDF.js MurmurHash3_64 source walkthrough: seed initialization, string and TypedArray normalization, alternating 32-bit lanes, tail-block mixing, the finalized 16-digit digest, and real internal uses.
October 27, 2026 · StreamPDF Team

PDF.js scripting_utils source walkthrough: the exact ColorConverters exports, normalized and 0–255 component contracts, HTML color formatting, transparent sentinels, and index-based Acrobat date/time presets.
October 27, 2026 · StreamPDF Team

A source walkthrough of PDF.js css_utils.js: how control-character checks, CSS string recognition, and font-family serialization keep PDF-originated names safe across FontFace, @font-face, and XFA style boundaries.
October 27, 2026 · StreamPDF Team

A focused source walkthrough of PDF.js MathClamp: inclusive boundary behavior, NaN and reversed-bound semantics, real callers from sampled functions to editor geometry, and why this temporary compatibility helper has its own module.
October 27, 2026 · StreamPDF Team

A source walkthrough of PDF.js internal_evt.js: build-time UUID injection, the frozen internalOpt capability, mirrored library and viewer modules, and how EventBus separates internal listeners from external delivery order.
October 27, 2026 · StreamPDF Team

A source walkthrough of the PDF.js data supply layer: the reader contract of BasePDFStream, the four implementations (fetch/XHR/Node/push), the five-gate validation behind range support, where the 64KB rangeChunkSize actually takes effect, and how the GetReader/GetRangeReader messages pump bytes into the worker.
October 27, 2026 · StreamPDF Team

A source walkthrough of PDFObjects, the main-thread object-readiness coordinator in PDF.js: the INITIAL_DATA three-state model, Promise.withResolvers entries, the dual synchronous/callback get contract, document-level and page-level stores, render dependency suspension, and ImageBitmap cleanup.
October 27, 2026 · StreamPDF Team

PDF.js source walkthrough: decoding commonobj ArrayBuffers into fonts, patterns, and glyph paths, including field offsets, byte order, on-demand getters, and clearData memory release.
October 27, 2026 · StreamPDF Team

The complete main-thread font loading path in PDF.js: FontFace registration, system fonts, legacy load detection, glyph path caching, and CanvasGraphics consumption.
October 27, 2026 · StreamPDF Team

A PDF.js TextLayer source walkthrough: how streamTextContent/getTextContent data becomes a transparent DOM text layer aligned with Canvas glyphs, providing structure for selection, copying, search, and accessibility.
October 27, 2026 · StreamPDF Team