Skip to main content

How I Built a Client-Side PDF Splitter With No Uploads

100% client-side PDF splitting, page extraction, and merging in JavaScript with pdf-lib and zero file uploads.

Updated 4 min readMarkdown

Every time I needed to split a bank statement, extract a few pages from a contract, or merge two PDFs, I ran into the same uncomfortable tradeoff: most popular online PDF tools ask you to upload your files to a remote server first.

Even when a site promises to delete files after an hour, uploading sensitive documents—tax forms, invoices, ID scans, legal agreements—to a third-party server just to split a few pages never felt right. And on top of the privacy concern, server-side processing costs money, which is why most online PDF tools eventually add file size limits, daily quotas, watermarks, or sign-up walls.

So I built ChopPDF: a free web tool that splits, extracts, and merges PDFs 100% client-side inside your browser, with zero file uploads.

Why Client-Side PDF Processing Makes Sense

Splitting, reordering, and merging PDFs does not require heavy server-side rendering or OCR. At its core, a PDF is a structured container of objects and a page tree. Copying selected page objects into a new PDF document is mostly byte-level manipulation in memory.

Modern browsers already give us everything needed to do this fast and safely on the user's own device:

  • File.arrayBuffer() to read local files directly into memory without touching the network
  • Mature client-side PDF libraries (such as pdf-lib) to parse, copy, and assemble pages in JavaScript
  • Blob and URL.createObjectURL() to trigger instant local downloads
  • Client-side ZIP packaging when splitting a multi-page document into individual files

How the Local Pipeline Works

The entire workflow stays inside the browser tab:

import { PDFDocument } from 'pdf-lib';

// 1. Read the PDF directly from the user's file input (no fetch / upload)
const bytes = await file.arrayBuffer();
const srcDoc = await PDFDocument.load(bytes);

// 2. Create a new PDF containing only the selected 0-based page indices
const selectedIndices = [0, 2, 3];
const outDoc = await PDFDocument.create();
const copiedPages = await outDoc.copyPages(srcDoc, selectedIndices);
copiedPages.forEach((page) => outDoc.addPage(page));

// 3. Serialize to bytes and trigger a local download
const outBytes = await outDoc.save();
const blob = new Blob([outBytes], { type: 'application/pdf' });
const url = URL.createObjectURL(blob);

const a = document.createElement('a');
a.href = url;
a.download = 'extracted-pages.pdf';
document.body.appendChild(a);
a.click();
a.remove();

// 4. Defer revoking the Blob URL so async downloads finish cleanly in Safari/Firefox
setTimeout(() => URL.revokeObjectURL(url), 1000);

When splitting every page of a document into separate numbered PDFs, each page is generated in memory and bundled into a single .zip archive locally so the browser only triggers one clean download instead of spamming dozens of download prompts.

One caveat worth calling out early is encrypted PDFs. Passing PDFDocument.load(bytes, { ignoreEncryption: true }) only bypasses metadata-level permission flags (an owner password with no open password). If a document requires an actual user password to open, skipping that flag will not decrypt the content stream—exporting pages will fail or produce blank/corrupted output, so it is much safer to check srcDoc.isEncrypted upfront and show a clear message.

Practical Lessons Learned

  1. Always clean up object URLs and buffers: Large scanned PDFs can easily be 50–100 MB. Revoking Blob URLs after download and avoiding duplicate copies of Uint8Array buffers keeps tab memory usage predictable.
  2. Make page selection effortless: Supporting simple custom ranges when users need to extract pages from a PDF in a custom order (like 4, 1-2)—or merge PDF files locally without hitting file-count paywalls—covers most real-world document workflows without cluttering the UI.
  3. Zero server compute = sustainable free tool: Because there is no backend processing queue or storage bill scaling with user files, the tool can stay free without accounts, upload caps, or watermarks—even on locked-down work laptops or Chromebooks where installing desktop software is not an option.

Verify It Yourself

If you want to test it—or verify that no file data leaves your browser—open Chrome DevTools, switch to the Network tab, open ChopPDF, and drop in a PDF (you can even turn off Wi-Fi after loading the page—splitting, extracting, and merging still work completely offline with zero upload requests).

I would love to hear feedback from fellow developers—especially edge cases you have hit with malformed PDFs, non-standard fonts, or huge scanned documents in the browser!

No comments yet. Be the first to comment.