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

join-pdf

v1.0.3

Published

Programmatically join any number of PDF files in arbitrary page orders.

Downloads

106

Readme

join-pdf 🧩🧩🧩

A Node.js + TypeScript module and CLI tool to combine multiple PDF files with full control over page order, duplication, and insertion of blank pages.
You can use it as a CLI command or as a programmatic library inside your Node projects.

License: MIT Node.js version


Installation

# install locally in your project
npm install join-pdf
# enable the CLI in a single project
npm link join-pdf 

# or install globally to use as a CLI command everywhere
npm install -g join-pdf

CLI Usage

Once installed globally, you can use the join-pdf command directly in your terminal.

Basic Syntax

join-pdf [command] [options]

Commands

1. list

Lists all requested PDFs and their total page counts.

join-pdf list file1.pdf file2.pdf file3.pdf

Example Output:

┌─────────┬────────────┬──────────────┐
│ (index) │ file       │ totalPages   │
├─────────┼────────────┼──────────────┤
│ 0       │ file1.pdf  │ 12           │
│ 1       │ file2.pdf  │ 7            │
└─────────┴────────────┴──────────────┘

2. validate

Validates a join definition before combining PDFs.
It checks whether page references exist and reports how often each source page is used.

join-pdf validate file1.pdf file2.pdf --join joinlist.json

or define the join inline using --pages:

join-pdf validate file1.pdf file2.pdf --pages "0:1,blank,1:2-4,0:5"

Example Output:

✅ No validation errors found.

📘 Usage Summary:
- file1.pdf: 1(1×), 5(1×) / total 12
- file2.pdf: 2(1×), 3(1×), 4(1×) / total 7

3. join

Creates a new combined PDF according to a defined page order.

Option A — using a JSON join list
join-pdf join file1.pdf file2.pdf --join joinlist.json --out result.pdf

joinlist.json Example:

[
  { "pdf": 0, "page": 1 },
  { "blank": true },
  { "pdf": 1, "page": "2-4" },
  { "pdf": 0, "page": 5 }
]
Option B — inline with --pages
join-pdf join file1.pdf file2.pdf --pages "0:1,blank,1:2-4,0:5" --out result.pdf

Options Summary

| Option | Description | Example | |--------|--------------|----------| | -j, --join <file> | Path to a JSON join definition file | --join joinlist.json | | -p, --pages <definition> | Inline page definition string | --pages "0:1,blank,1:2-4" | | -o, --out <file> | Output file name | --out result.pdf | | --help | Show command help | join-pdf join --help |


Page Definition Syntax (--pages)

Each token in the --pages string is separated by commas:

| Token Type | Meaning | Example | |-------------|----------|----------| | 0:1 | Page 1 from first PDF | 0:1 | | 1:2-4 | Pages 2 through 4 from second PDF | 1:2-4 | | blank | Insert a blank page | blank |

PDFs are indexed starting at 0, in the order they are listed on the command line.


Programmatic Usage in Node.js

You can also use join-pdf as a module in your Node.js or TypeScript projects.

🔹 Import

import { listPdfs, join, validateList } from "join-pdf";

async listPdfs(pdfs: string[]): Promise<{ file: string; totalPages: number }[]>

Reads all given PDFs and returns their total page counts.

const info = await listPdfs(["a.pdf", "b.pdf"]);
console.log(info);

Example Output:

[
  { file: "a.pdf", totalPages: 12 },
  { file: "b.pdf", totalPages: 7 }
]

async join(pdfs: string[], joinList: JoinItem[]): Promise<Uint8Array>

Combines PDFs according to a defined page order.

const joinList = [
  { pdf: 0, page: 1 },
  { blank: true },
  { pdf: 1, page: "2-4" },
  { pdf: 0, page: 5 }
];

const bytes = await join(["a.pdf", "b.pdf"], joinList);
await fs.writeFile("output.pdf", bytes);

✅ You can reuse or skip pages
✅ You can insert blank pages (A4 portrait) ✅ You can use page ranges like "2-5"


async validateList(pdfs: string[], joinList: JoinItem[]): Promise<TestResult>

Validates that all referenced pages exist and reports usage.

const result = await validateList(["a.pdf", "b.pdf"], joinList);

if (result.errors.length) {
  console.error("Errors:", result.errors);
} else {
  console.log("Usage:", result.usage);
}

Example Output:

{
  errors: [],
  usage: [
    { file: "a.pdf", totalPages: 12, usedPages: { "1": 1, "5": 1 } },
    { file: "b.pdf", totalPages: 7, usedPages: { "2": 1, "3": 1, "4": 1 } }
  ]
}

JSON JoinList Format

Each item in the join list is an object with one of the following forms:

| Type | Example | Description | |------|----------|-------------| | Single Page | { "pdf": 0, "page": 1 } | Take page 1 from first PDF | | Page Range | { "pdf": 1, "page": "3-5" } | Take pages 3–5 from second PDF | | Blank Page | { "blank": true } | Insert a blank page |


Example Project Structure

my-project/
├─ src/
│  ├─ join-pdf.ts
│  └─ cli.ts
├─ package.json
└─ joinlist.json

Tips

  • You can reuse pages multiple times (e.g., { "pdf": 0, "page": 1 } repeated).
  • Non-consecutive pages are supported — order is fully flexible.
  • validateList helps ensure all requested pages exist before joining.
  • Works best with Node.js v18+.

License

MIT © 2025 Florian Walzel