I built 100 PDF tools that never upload your file. Here's how the browser does it all.
Most online PDF tools work the same way: you upload a file, a server processes it, and you download the result. That is fine for a flyer. It is less fine for a bank statement, a contract, or a passport scan.
I wanted the same tools without the upload, so I built KissThePDF. It is open source (MIT), has about 100 tools, and has no backend for files at all. Your PDF is read, processed and saved inside the browser tab.
This post covers how it works and the parts that were awkward.
Three engines, three jobs
No single library does everything, so the app uses three:
| Engine | Job |
|---|---|
| pdf-lib | Structural edits: merge, split, reorder, rotate, forms, metadata |
| PDF.js | Rendering pages to canvas for thumbnails, previews and image export |
| qpdf (WebAssembly) | Real encryption, password removal and permission flags |
pdf-lib is pure JavaScript and covers most tools. Merging two files is short:
import { PDFDocument } from "pdf-lib";
const out = await PDFDocument.create();
for (const bytes of inputs) {
const src = await PDFDocument.load(bytes);
const pages = await out.copyPages(src, src.getPageIndices());
pages.forEach((p) => out.addPage(p));
}
const merged = await out.save();
What pdf-lib cannot do is encrypt. For AES-256 and password removal I needed qpdf, which is a C++ command-line tool.
Running a C++ CLI in the browser
qpdf compiles to WebAssembly through Emscripten. You get a virtual filesystem and a callMain function, so you use it like a CLI: write the input file, pass arguments, read the output file.
q.FS.writeFile(inPath, input);
const code = q.callMain([inPath, "--decrypt", outPath]);
const output = q.FS.readFile(outPath).slice();
Three things caught me out:
- The build ignores
printandprintErr. Emscripten modules normally let you pass functions to capture stdout and stderr. This build bindsconsole.logandconsole.errorwhen the factory runs and keeps those references forever. To read qpdf's messages (such as "invalid password"), I swap in capturing wrappers for the moment the module is created, then restore the originals straight away. - Exit code 3 is success.
qpdfreturns 3 for "worked, with warnings", which is common for slightly broken real-world files. Treating anything non-zero as failure rejects PDFs that converted fine. - It should not be bundled. The module is a UMD script that fetches its own
.wasmat runtime, about 1.3 MB in total. A build script copies both files into/public/vendor, and a<script>tag loads them the first time a security tool needs them. No other page pays for that download.
100 tools without a 100-tool bundle
Every tool is one React component with a default export, registered by id:
export const pagesTools: ToolLoaders = {
"reverse-pages": () => import("./ReversePages"),
};
Each import() becomes its own chunk, so opening "Reverse Pages" downloads only that tool and the libraries it uses. One central config file drives routing, the sidebar and page metadata, so adding a tool means one component and one registry line.
Tools touch canvas, File and workers at module scope, so they are never rendered on the server. The explanatory content around each tool is server-rendered, and the tool mounts on the client inside Suspense with React's use().
Rules I set for every tool
A few rules live in the repo's contributor guide, and they shaped the code more than any library choice:
- Never lie about a result. If a tool cannot do the job for this file (a scanned page with no text, a form with no fields), it says so. It does not hand back an unchanged file that looks done.
- Errors a person can act on. A locked PDF gets a message pointing to the unlock tool, not a stack trace.
- Don't freeze the tab. Long loops report progress, check for cancellation, and release canvases after rendering.
What it does not do
- OCR and Office conversion. Word and Excel conversion is hard to do well client-side, and I have not found an approach I'm happy with.
- Huge files. Everything lives in browser memory, so the limit is your device, not a server quota.
- Zero third-party requests. The site loads Google Analytics for page views. No request carries your file, and you can check that in the Network tab.
Try it or read the code
Live: kissthepdf.space
Code: github.com/positiveabhii/kiss-the-pdf
If a tool breaks on one of your PDFs, please open an issue. And if you have shipped OCR or DOCX conversion in the browser, I would like to hear how you did it.
Comments
No comments yet. Start the discussion.