ProvenPin Install

pdf-lib create and read invoice PDF: working versions (tested 2026-10-15)

Build a multi-page invoice PDF with pdf-lib, draw text and rectangles, then reload the bytes and assert page count offline.

passed1 passed · 0 failed2026-10-15 16:03 UTC
Status
passed
Last passed
2026-10-15 16:03 UTC
Tests
1 / 1
Language
TypeScript
Runtime
node v22.23.3
pinned versions3
pdf-lib@1.17.1@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38764699834

The code

Exactly the files that passed. Your agent can pull them with get_recipe("pdf-lib-invoice") (install), or see them on GitHub.

package.json
{
  "name": "pdf-lib-invoice",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {"pdf-lib":"1.17.1"},
  "devDependencies": {"@types/node":"26.6.5","tsx":"4.23.15"}
}
src/invoice.ts
import { PDFDocument, StandardFonts, rgb } from "pdf-lib";

export type Invoice = {
  number: string;
  customer: string;
  lines: { description: string; amount: string }[];
};

export async function buildInvoicePdf(invoice: Invoice) {
  const doc = await PDFDocument.create();
  const page = doc.addPage([612, 792]);
  const font = await doc.embedFont(StandardFonts.Helvetica);
  const bold = await doc.embedFont(StandardFonts.HelveticaBold);

  page.drawText(`Invoice ${invoice.number}`, { x: 50, y: 740, size: 18, font: bold });
  page.drawText(`Bill to: ${invoice.customer}`, { x: 50, y: 710, size: 12, font });
  page.drawRectangle({ x: 50, y: 680, width: 512, height: 1, color: rgb(0.7, 0.7, 0.7) });

  let y = 650;
  for (const line of invoice.lines) {
    page.drawText(line.description, { x: 50, y, size: 11, font });
    page.drawText(line.amount, { x: 480, y, size: 11, font });
    y -= 20;
  }

  const bytes = await doc.save();
  return Buffer.from(bytes);
}

export async function pageCount(pdfBytes: Uint8Array) {
  const doc = await PDFDocument.load(pdfBytes);
  return doc.getPageCount();
}
test/invoice.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { buildInvoicePdf, pageCount } from "../src/invoice.ts";

test("builds a readable one-page invoice", async () => {
  const pdf = await buildInvoicePdf({
    number: "INV-100",
    customer: "Ada Lovelace",
    lines: [
      { description: "Consulting", amount: "$120.00" },
      { description: "Hosting", amount: "$15.00" },
    ],
  });
  assert.equal(pdf.subarray(0, 4).toString("utf8"), "%PDF");
  assert.equal(await pageCount(pdf), 1);
  assert.ok(pdf.length > 500);
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.