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-reorder-pages

v0.1.0

Published

Reorder the pages of a PDF in JavaScript, in Node.js or the browser. Nothing is uploaded.

Readme

@utilitly/pdf-reorder-pages

Reorder PDF pages in JavaScript: pass the page numbers in the order you want, get back a PDF in that order. Works in Node.js and in the browser, and nothing is uploaded.

On the Reorder PDF Pages tool on utilitly.com you drag thumbnails around. This package is the same job for code: hand over the new order as an array, and every page is checked off before a single byte is written.

Install

npm install @utilitly/pdf-reorder-pages

Comes as ESM and CommonJS with TypeScript types. Its single dependency is pdf-lib.

Reorder pages in 30 seconds

In Node.js, moving a summary from the back of a deck to the front:

import { readFile, writeFile } from 'node:fs/promises'
import { reorderPages } from '@utilitly/pdf-reorder-pages'

const deck = await reorderPages(await readFile('deck.pdf'), [6, 1, 2, 3, 4, 5])
await writeFile('deck-summary-first.pdf', deck)

In the browser, saving the order a user arranged in a drag-and-drop list:

import { reorderPages } from '@utilitly/pdf-reorder-pages'

// thumbnails: the list items in their new order, each with data-page="2" etc.
const order = [...thumbnails].map(item => Number(item.dataset.page))
const rearranged = await reorderPages(await file.arrayBuffer(), order)

API

reorderPages(pdf, order)

Returns Promise<Uint8Array>: a new PDF whose pages follow order.

| Parameter | Type | | | --- | --- | --- | | pdf | Uint8Array \| ArrayBuffer | The PDF; a Node.js Buffer is fine. | | order | number[] | Page numbers, starting at 1, listing every page exactly once. [3, 1, 2] puts page 3 first. |

order is checked against the document before anything is copied. A page that's missing, a page listed twice and a number past the last page each stop the call with a message naming the page, so a typo can't silently lose part of a document. To leave pages out on purpose, use @utilitly/pdf-delete-pages.

Errors

The code on each PdfError tells you what went wrong:

| code | When | | --- | --- | | INVALID_OPTIONS | order isn't an array of whole numbers from 1 up, or it misses, repeats or overshoots a page. | | NOT_A_PDF | The input doesn't parse as a PDF. | | ENCRYPTED | The document has a password; take it off before reordering. | | INVALID_INPUT | pdf is neither a Uint8Array nor an ArrayBuffer. |

Why nothing is uploaded

Reordering is pure bookkeeping on data you already have, so there's no reason for it to leave the machine, and it doesn't. pdf-lib rebuilds the page list in memory where you call reorderPages; the Network panel records nothing.

Good to know

  • Pages are copied into the new order in one pass, so an image or font shared by several pages is stored once.
  • Each page keeps its size and rotation.
  • The output is a new PDF: bookmarks, title and author, and working form fields aren't carried across, and its producer is pdf-lib. Field boxes remain visible on the page.

License

MIT. Built on pdf-lib, also MIT.

More engines from Utilitly: merge · split · rotate · delete pages · duplicate pages