Merge PDFs in the browser with JavaScript (no uploads, no server)
In this post I'll show how to merge PDF files entirely in the browser using PDF.js and pdf-lib — no server, no file upload, no backend. Everything runs on the user's machine, which is great for privacy and for keeping hosting costs at zero (it's just a static site). Why process PDFs on the client? Most "free" PDF websites quietly upload your documents to their server, which: Exposes…
This article explains how to merge PDF files entirely in the browser using JavaScript, without the need for server-side processing or file uploads. The approach utilizes two main libraries: PDF.js for rendering PDFs in the browser and pdf-lib for manipulating PDF data directly within the browser. This method ensures privacy, as the user's files never leave their device, and eliminates the cost of maintaining a backend server.
However, there are some limitations to consider. The pdf-lib library works best with standard PDFs, and heavily encrypted or unusual documents may require additional handling. Additionally, very large PDFs can be memory-intensive since all processing happens on the user's machine. While most standard documents process quickly and free of cost, some complex files with unusual fonts might experience reduced fidelity.
The author has packaged this technique, along with other PDF manipulation features like splitting, compressing, rotating, unlocking, and converting images to PDF, into a free no-upload tool available at https://yourutilityhub.com/pdf/merge-pdf. The complete source code is open source on GitHub at https://github.com/Jalal-khn/utilityhub-.
For those interested in the technical details or seeking to explore specific aspects of the implementation, they are encouraged to reach out. The core function for merging PDFs is provided in JavaScript, using PDFDocument from pdf-lib to create a new document, load source files with encryption ignored, copy pages from the input documents into the new one, and finally save and download the merged PDF.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.