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

pdf-merge-split

v1.0.7

Published

Fast and simple PDF merge and split library for Node.js

Readme

This package pdf-merge-split performe merge and split opreation on pdf, provide prebuild function, It use pdf-lib

Installation

npm i pdf-merge-split

merge pdf

commonjs

const {merge_pdf} = require('pdf-merge-split')
const fs = require('fs')

const paths = ['./test.pdf','./test2.pdf']

async function mergePdf_fn() {
    const pdf_data = await merge_pdf(paths);
    if (pdf_data.success) {
        fs.writeFileSync('merge.pdf', pdf_data.data)
    }
}

mergePdf_fn()

ES6

import {merge_pdf} from 'pdf-merge-split'
import fs from 'fs'

const paths = ['./test.pdf','./test2.pdf']

const mergePdf_fn = async () => {
    const pdf_data = await merge_pdf(paths);
    if (pdf_data.success) {
        fs.writeFileSync('merge.pdf', pdf_data.data)
    }
}

mergePdf_fn()

Input

merge_pdf accepts one argument:

  • An array of PDF file paths

Rules

  • Must be an array of strings
  • Minimum 2 file paths required
  • You can add as many PDF files as needed

Output

merge_pdf returns an object:

{
  success: Boolean,
  data: Buffer
}
  • success => true only if merge is successful
  • data => final merged PDF (raw buffer, must be saved as .pdf)
  • If success = false, data will NOT be returned

split pdf

allpagesplit (split each page of pdf as separate pdf file)

commonjs

const {split_pdf} = require('pdf-merge-split');
const fs = require('fs');

const option = {
   mode: 'allpagesplit'
}
async function splitPdf_fn() {
  const pdf_data = await split_pdf('./test.pdf', option);
  if (pdf_data.success) {
     for (let i = 0; i < pdf_data.totalPages; i++) {
     fs.writeFileSync(`${i+1}.pdf`,pdf_data.data[i])
    }
  }
}
splitPdf_fn()

ES6

import {split_pdf} from 'pdf-merge-split'
import fs from 'fs'

const option = {
    mode: 'allpagesplit'
}
const splitPdf_fn = () => {
    const pdf_data = await split_pdf('./test.pdf', option);
  if (pdf_data.success) {
     for (let i = 0; i < pdf_data.totalPages; i++) {
     fs.writeFileSync(`${i+1}.pdf`,pdf_data.data[i])
    }
  }
}
splitPdf_fn()

range (split each page of pdf as separate pdf file for given range , ex: 10, 15 => output => 10.pdf , 11.pdf .... to 15.pdf, give range inside option pageNumbers field)

commonjs

const {split_pdf} = require('pdf-merge-split');
const fs = require('fs');

const option = {
   mode: 'range',
   pageNumbers: [10,15]
}

const splitPdf_fn = () => {
    const pdf_data = await split_pdf('./test.pdf', option);
    if (pdf_data.success) {
     for (let i = 0; i < pdf_data.totalPages; i++) {
      fs.writeFileSync(`${i+1}.pdf`,pdf_data.data[i])
  }
 }
}

splitPdf_fn()

ES6

import {split_pdf} from 'pdf-merge-split'
import fs from 'fs'

const option = {
   mode: 'range',
   pageNumbers: [10,15]
}
const splitPdf_fn = () => {
    const pdf_data = await split_pdf('./test.pdf', option);
  if (pdf_data.success) {
     for (let i = 0; i < pdf_data.totalPages; i++) {
     fs.writeFileSync(`${i+1}.pdf`,pdf_data.data[i])
    }
  }
}
splitPdf_fn()

pagenumber (split each page of pdf as separate pdf file for given page numbers , ex : 10, 15 => output => 10.pdf, 15.pdf, give pagenumber inside option pageNumbers field)

commonjs

const {split_pdf} = require('pdf-merge-split');
const fs = require('fs');

const option = {
   mode: 'pagenumber',
   pageNumbers: [10,15]
}
const splitPdf_fn = () => {
    const pdf_data = await split_pdf('./test.pdf', option);
  if (pdf_data.success) {
     for (let i = 0; i < pdf_data.totalPages; i++) {
     fs.writeFileSync(`${i+1}.pdf`,pdf_data.data[i])
    }
  }
}

splitPdf_fn()

ES6

import {split_pdf} from 'pdf-merge-split'
import fs from 'fs'

const option = {
   mode: 'pagenumber',
   pageNumbers: [10,15]
}
const splitPdf_fn = () => {
    const pdf_data = await split_pdf('./test.pdf', option);
  if (pdf_data.success) {
     for (let i = 0; i < pdf_data.totalPages; i++) {
     fs.writeFileSync(`${i+1}.pdf`,pdf_data.data[i])
    }
  }
}

splitPdf_fn()

Input

split_pdf accept two argumenst:

  • pdf path (string)
  • option (object)

option

  • mode (string)
    • allpagesplit (split each page of pdf as separate pdf file)
    • range (split each page of pdf as separate pdf file for given range , ex: 10, 15 => output => 10.pdf , 11.pdf .... to 15.pdf)
    • pagenumber (split each page of pdf as separate pdf file for given page numbers , ex : 10, 15 => output => 10.pdf, 15.pdf)
  • pageNumbers (Array of Number) (total length must be excat 2) (only required for mode range and pagenumber)

option for allpagesplit

const option = {
    mode: "allpagesplit"
}

option for range

const option = {
    mode: "range",
    pageNumbers: [10,15]
}

option for pagenumber

const option = {
   mode: 'pagenumber',
   pageNumbers: [10,15]
}

Output

{
  success: Boolean,
  data: [] Buffer,
  totalPages: Number
}
  • success : return true if all ok
  • data : array of buffer raw data, each element is separate pdf
  • totalPages : length of data