npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@utilitly/pdf-merge

v0.1.0

Published

Merge PDF files in JavaScript, in Node.js or the browser. Nothing is uploaded.

Readme

@utilitly/pdf-merge

Merge PDF files in JavaScript with one function call. It runs in Node.js and in the browser, and the files never leave the machine that runs it.

Hand mergePdfs an array of PDFs and you get back a single PDF with every page, in the order you passed them. There's no server to call, no API key and no upload step. It's the merge logic from the Merge PDF tool on utilitly.com, packaged for your own code.

Install

npm install @utilitly/pdf-merge

Ships ESM and CommonJS builds with TypeScript types. Its one dependency is pdf-lib.

Merge PDFs in 30 seconds

In Node.js:

import { readFile, writeFile } from 'node:fs/promises'
import { mergePdfs } from '@utilitly/pdf-merge'

const book = await mergePdfs([
  await readFile('cover.pdf'),
  await readFile('chapter-1.pdf'),
  await readFile('chapter-2.pdf'),
])
await writeFile('book.pdf', book)

In the browser, straight from a file input:

import { mergePdfs } from '@utilitly/pdf-merge'

// files: the FileList from <input type="file" accept="application/pdf" multiple>
const merged = await mergePdfs(await Promise.all([...files].map(file => file.arrayBuffer())))
const url = URL.createObjectURL(new Blob([merged], { type: 'application/pdf' }))

API

mergePdfs(pdfs, options?)

Returns Promise<Uint8Array>: the bytes of the merged PDF.

| Parameter | Type | | | --- | --- | --- | | pdfs | Array<Uint8Array \| ArrayBuffer> | At least one PDF. A Node.js Buffer works as-is. | | options.onProgress | (done, total) => void \| Promise<void> | Called after each file is added. If it returns a promise, merging waits for it, so a UI can repaint between files. |

await mergePdfs(pdfs, {
  onProgress: (done, total) => console.log(`${done} of ${total} files`),
})

Errors

Every failure is a PdfError with a code you can switch on:

| code | When | | --- | --- | | INVALID_OPTIONS | pdfs isn't an array, or it's empty. | | INVALID_INPUT | One of the items isn't a Uint8Array or ArrayBuffer. | | NOT_A_PDF | One of the files can't be parsed as a PDF. The message names it: File 2 could not be read as a PDF. | | ENCRYPTED | One of the files is password-protected. Remove its password first. |

Why nothing is uploaded

Merging happens in the same JavaScript process that calls mergePdfs. This package and pdf-lib contain no network code, so the PDFs stay in memory where you put them. Open DevTools while it runs and the Network panel has nothing to show. That makes it a fit for contracts, medical records and anything else you shouldn't hand to a third-party API.

Good to know

  • Pages keep their own size and rotation, so a Letter page and a sideways A4 page sit side by side in the output.
  • Each file's pages are copied in one pass, so an image or font shared by several pages of a file is embedded once, not once per page.
  • Bookmarks (the document outline) aren't carried over, and neither are document properties such as title and author. The merged file starts fresh, with pdf-lib as its producer.
  • Form fields stop being interactive. The boxes stay visible on the page, but the merged PDF no longer lists them as fields.

License

MIT. Built on pdf-lib, also MIT.

Other Utilitly PDF engines: split · rotate · delete pages · reorder pages · duplicate pages