We have all been there. You need to combine three PDFs for a tax filing or a job application, so you search for a quick tool online. You end up uploading sensitive documents containing your SSN, address, or financial history to a mysterious, ad-ridden server.
As a developer, this always rubbed me the wrong way. Why do we need to send megabytes of personal data over the wire just to append a few byte streams together? The answer is: we don't.
I set out to build a completely free, zero-registration PDF merger that does 100% of the heavy lifting right inside the user's browser. No backend APIs, no remote servers, and absolutely zero data leaks. Here is how I did it.
The Tech Stack: Running it All in the Browser
To achieve zero-server processing, I needed a library that could parse, modify, and serialize PDF documents completely on the client side. I chose pdf-lib due to its robust API and active ecosystem.
Unlike traditional server-side rendering tools (like PDFKit or standard CLI tools), pdf-lib allows us to load PDFs as binary ArrayBuffer data arrays directly in the browser's memory space.
Here is the high-level architecture of the merge process:
- The user drags and drops their files.
- The browser reads the files as
ArrayBufferusing the HTML5FileReaderAPI. - We instantiate a new
PDFDocumentin memory. - We loop through each uploaded file, load it via
pdf-lib, copy the pages, and add them to the main document. - The combined PDF is serialized back into a
Uint8Arrayand instantly triggered as a local browser download.
Overcoming Browser Constraints
While client-side processing is incredible for privacy, it comes with a major bottleneck: browser memory limits.
If a user tries to merge five 50MB PDFs on a low-end mobile device, the browser tab will easily crash due to out-of-memory (OOM) errors.
To solve this, I implemented several optimizations:
- Garbage Collection Optimization: Explicitly dereferencing massive arrays and forcing garbage collection paths.
- Asynchronous Chunking: Processing page copying in sequential chunks rather than all at once, preventing the UI thread from freezing.
- On-the-Fly Compression: Strip out unnecessary metadata and duplicate font definitions that often bloat merged files.
The Result
The result of this weekend project is pdfmergeapp.com. It is incredibly fast because there is zero network latency for uploads or downloads. Best of all, if you inspect the network tab while using it, you will see exactly zero outbound requests containing your document data.
Iβd love to hear your thoughts on optimization tricks for handling even larger files (100MB+) purely in the browser. Have you experimented with WebAssembly or Web Workers for client-side file manipulation? Letβs chat in the comments!

Top comments (0)