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

@libs-jd/pdf-lib-bulk

v0.1.1

Published

Bulk PDF generation for pdf-lib — font parsing cached across documents (4x) and template cloning for identical documents (31x). Generate 100k PDFs without re-parsing the font 100k times.

Readme

pdf-lib-bulk

npm version license

Bulk PDF generation for pdf-lib — without re-parsing your font for every single document.

pdf-lib calls fontkit.create(bytes) inside every embedFont(). Generate 100,000 invoices and you parse the same TTF 100,000 times. This library amortizes that away:

| Workload (100 one-page PDFs, custom TTF, Apple M1) | pdf-lib naive | pdf-lib-bulk | Speedup | | --- | --- | --- | --- | | Variable text per document (bulkGenerate) | 1,399 ms | 347 ms | 4.0x | | Identical documents (makeTemplateCloner) | 1,515 ms | 48 ms | 31x |

Reproduce with bun run bench/bench.ts.

Install

npm install @libs-jd/pdf-lib-bulk pdf-lib @pdf-lib/fontkit

Usage

Variable content per document (invoices, letters, tickets)

import fontkit from "@pdf-lib/fontkit";
import { bulkGenerate } from "@libs-jd/pdf-lib-bulk";

const fontBytes = await fs.promises.readFile("Inter-Regular.ttf");

const pdfs = await bulkGenerate(invoices, {
  fontkit,                       // parsed once, reused for every document
  fonts: { body: fontBytes },
  draw({ doc, fonts, item }) {
    const page = doc.addPage();
    page.drawText(`Invoice #${item.id} — ${item.total}`, {
      x: 50, y: 700, size: 24, font: fonts.body,
    });
  },
});
// pdfs: Uint8Array[] — one standalone PDF per invoice

Identical documents (certificates, blank forms)

import { makeTemplateCloner } from "@libs-jd/pdf-lib-bulk";

// build the document once, however you like (fonts embedded once, layout once)
const templateBytes = await buildCertificateTemplate();

const cloner = await makeTemplateCloner(templateBytes);
const pdfs = await cloner.cloneMany(10_000);

Just the font cache

If you want to keep your own generation loop, wrap fontkit yourself:

import fontkit from "@pdf-lib/fontkit";
import { cachingFontkit } from "@libs-jd/pdf-lib-bulk";

const fk = cachingFontkit(fontkit);
// ...
doc.registerFontkit(fk);                     // same API, parse happens once
const font = await doc.embedFont(fontBytes, { subset: true });

How it works

  • cachingFontkit — memoizes fontkit.create() per font buffer (WeakMap keyed by the Uint8Array you pass), so the expensive TTF/OTF parse happens once per font instead of once per document. Fonts are still embedded and subset per document, so every output PDF is standalone.
  • bulkGenerate — a generation loop with the cache pre-wired: create doc → embed cached fonts → your draw callback → save.
  • makeTemplateCloner — loads your finished template once and produces copies via copyPages, skipping layout, font parsing, and font embedding entirely.

About

Contributions welcome — please open an issue or PR. If this saved your batch job some hours, a ⭐ helps others find it.

Related

Author

Jeet DhandhaGitHub

License

MIT