Manipulation · Node.js and TypeScript
Merge PDF files in Node.js
Combine, split, reorder and rotate PDF pages from Node.js. rust-pdf parses each document into an editable model, renumbers and remaps every object correctly on merge, and rebuilds a clean page tree on output.
Last updated: 2026-06-29
Why Node.js and TypeScript needs this
Stitching PDFs together in Node often means one CLI call per operation, or a wrapper that only handles files it produced itself and breaks on real uploads.
Merging and splitting are list operations on a flat page order: append another document, extract a subset, reverse, rotate or delete pages, then save. Because the parser handles classic and cross-reference streams, object streams and encrypted input, it works on real-world files, not just ones it wrote itself.
Treat pages as a flat list: load each document, merge, reorderPages with a permutation, rotatePage, or extractPages a subset, then save. pageCount and the page methods are typed for autocomplete, and the parser reads object and cross-reference streams, so an Express upload route handles files from any producer, not just ones rust-pdf wrote.
- Merge whole documents, extract page subsets, reorder with a permutation, rotate or delete pages.
- Objects are renumbered and references deep-remapped, so merged files stay valid.
- Reads classic and xref streams, object streams and RC4 / AES encrypted input.
Merge PDFs in Node.js with rust-pdf
Install from npm, then work with pages as a flat list you append, rotate, reverse and slice. The snippet below is real Node.js from the reference docs.
npm install rustpdf
const a = EditableDoc.loadFile("a.pdf");
const b = EditableDoc.loadFile("b.pdf");
a.merge(b); // a now has a's pages followed by b's
a.rotatePage(0, 90);
a.reorderPages([...Array(a.pageCount).keys()].reverse());
a.save("merged.pdf");
b.close();
const subset = a.extractPages([0, 2]); // pages 1 and 3
subset.save("subset.pdf");
subset.close();
a.close();
Merging, splitting and reordering are part of the free tier in Node.js. No license token needed.
The full Node.js manipulation reference is in the documentation.
Merging in Node.js: FAQ
Can I merge more than two PDFs in Node.js?
Yes. Load each document and call merge for each one; pages are appended in order. You can then reorder, rotate or extract any subset before saving.
Does merging keep the files valid?
Yes. On merge every object from the other document is renumbered and its references are deep-remapped, and the real page tree is rebuilt on output, so the result passes qpdf and mutool.
Is merging free?
Yes. Loading, merging, splitting, reordering and text extraction are all part of the free tier in Node.js. You only need a license for the corporate features such as PDF/A, signatures and encryption.
Can I merge uploaded PDFs in an Express route without temp files?
Yes. The whole flow stays in process through the Koffi binding, so an Express or NestJS upload handler can load each document, merge, reorder or extract pages, and save the result without spawning a CLI or leaving scratch files on disk.
Assemble and split documents straight from your API
One Rust core, the same page operations in every language. Manipulation is free; license PDF/A, signatures or encryption only when you reach for them.