Technical Architecture6 min readUpdated September 2026

How PDF Merge Works: The Technical Mechanics of In-Browser Document Stitching

Merging PDFs seems conceptually simple: take Document A and Document B and glue them together. But under the hood of the ISO 32000 specification, a PDF is an intricate graph of interrelated dictionary objects, byte-offset tables, and compressed resource streams.

1. The Anatomy of a PDF File

Before understanding how two files combine, we must understand how a standalone PDF is structured. Unlike plain text or markup languages like HTML, a PDF is structured into four distinct physical sections:

// 1. Header
%PDF-1.7 (version declaration)
// 2. Body (Indirect Objects)
1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj
2 0 obj << /Type /Pages /Kids [3 0 R] /Count 1 >> endobj
3 0 obj << /Type /Page /Contents 4 0 R >> endobj
// 3. Cross-Reference Table (xref)
xref
0 5
0000000000 65535 f
0000000015 00000 n (Byte offset of Object 1)
// 4. Trailer
trailer << /Size 5 /Root 1 0 R >>
startxref 428 %%EOF

Notice the fundamental mechanism: the PDF reader starts reading from the very bottom of the file (the trailer). The trailer tells the reader the exact byte location of the xref table, which in turn maps every Object ID (e.g. 1 0 R, 2 0 R) to its exact physical position on disk.

2. The Challenge: Resolving Object ID Collisions

In Document A, Object 1 0 R might be the document root catalog. In Document B, Object 1 0 R might be a high-resolution photograph of a corporate logo. If you simply concatenated the byte streams of both files, the resulting document would corrupt instantly because of conflicting object identifiers.

To merge them safely, the merger must perform an operation known as Object Graph Renumbering:

  1. Document A Parsing: All indirect objects in Document A are assigned IDs from 1 to N.
  2. Document B Offset Translation: Every object in Document B is incremented by N (e.g., Object 1 becomes N + 1, Object 2 becomes N + 2).
  3. Internal Reference Rewriting: Every reference inside Document B pointing to an old ID is updated to its new offset index.

3. Unifying the Pages Tree

A PDF does not hold pages in an array; it holds pages in a hierarchical B-tree known as the /Pages dictionary. Each page node possesses a /Parent attribute pointing back up the tree.

When PDF Toolkit Pro merges documents:

  • A fresh, unpolluted /Pages root node is synthesized.
  • The /Kids array is populated with pointers to the renumbered page objects from both documents in the user-specified sequence.
  • The /Count property is set to the total page sum.
  • Shared resources such as embedded TrueType font subsets, color spaces, and graphics states are deduplicated where safe.

4. How We Do It 100% Inside Your Browser

Historically, merging required sending documents over HTTPS to a Python or Java microservice running Ghostscript or QPDF. This created massive security issues:

The Cloud Approach (Vulnerable)

Files travel over internet backbones to multi-tenant servers, stored on shared SSDs, exposing confidential medical or financial records to server logs and third-party breaches.

Our Client-Side Sandbox

The entire PDF parsing and serialization engine executes inside the browser’s JavaScript V8 engine using Web Workers and typed ArrayBuffers.

When you drag files into PDF Toolkit Pro’s Merge Tool, the browser uses the native HTML5 FileReader.readAsArrayBuffer() API. The PDF parser reconstructs the xref table and objects directly in RAM. Once you hit download, the binary byte array is wrapped in a local Blob object and downloaded directly from memory via URL.createObjectURL().

Summary

By taking advantage of modern browser capabilities, document workflows no longer need to sacrifice confidentiality for convenience. You get instant speeds, zero file upload queues, and absolute certainty that your contracts stay entirely in your possession.

Try Client-Side Merging Now

Free forever, zero uploads, unlimited pages.

Merge PDF Files