{
  "id": 17494074,
  "title": "Merge and compress PDFs in the browser with pdf-lib and PDF.js (no server, no upload)",
  "url": "https://urgent.news/2026/10/31/merge-and-compress-pdfs-in-the-browser-with-pdf-lib-and-pdf-js-no",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-31T23:46:22.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/ilovepdfe_com/merge-and-compress-pdfs-in-the-browser-with-pdf-lib-and-pdfjs-no-server-no-upload-5hc7"
  },
  "original_language": "en",
  "account": "Both PDF-lib and PDF.js enable merging and compressing PDFs directly in a user's web browser, eliminating the need for server-side processing or file uploads. This approach preserves user privacy and avoids potential security risks associated with transmitting sensitive documents to external servers.\n\nMerging PDFs is a straightforward task using pdf-lib. The process involves loading each input file, copying its pages into a new PDF document, and saving the combined output. The function mergePdfs accepts an array of file objects, loads each file, and appends its pages to the output document. The resulting merged PDF is then saved using object streams to optimize its size.\n\nCompressing a PDF primarily focuses on image content, as vector graphics and text are inherently compact. pdf-lib provides the useObjectStreams flag to enable object stream compression, which reduces the file size by about 5-15% for text-heavy PDFs. However, this method cannot re-encode embedded images. To achieve significant compression of scanned documents, rasterization is required. This involves rendering each page to a canvas, encoding it as a JPEG with a reduced quality setting, and creating a new PDF containing these compressed images. This approach is lossy, meaning some image quality is sacrificed, but it can result in substantial file size reductions.",
  "summary": "Most \"free PDF tools\" upload your file to a server, process it, and send it back. For a contract, a bank statement or a scanned ID, that is a real privacy cost, and it isn't necessary. Modern browsers can do most everyday PDF jobs locally. In this post I'll show the two operations people ask for most, merge and compress , using two libraries: pdf-lib to create and modify PDF documents. PDF.js…",
  "key_points": [
    "pdf-lib and PDF.js enable browser-based PDF merging and compression",
    "MergePdfs function combines input files into a single output document",
    "Object stream compression reduces text-heavy PDFs by 5-15%"
  ],
  "editors_take": "Shifting document processing from external servers to the local browser strengthens user privacy by ensuring sensitive files never leave the client's machine during the merging or compression process.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}