Free pdf-lib (pdflib) Templates & Coordinate Code Generator
Pure TypeScript PDF object & vector builder with zero native binaries — runs in browsers, Node.js, Deno, Bun, and Cloudflare Workers, and can also open, edit, merge, or fill AcroForms in existing PDFs (5.3 ms single-page; 334 ms & 203.8 KB on our 20-page stress test).
Install: npm install pdf-lib@^1.17.1 | Runtime: Node.js (TypeScript / JS) | Version: 1.17.1 | Popularity: 5.1M/mo installs
Works with: Node.js, Browser, Next.js, Cloudflare Workers, Deno, Bun
How pdf-lib Templates Work in CodePDF
pdf-lib operates on raw PDF primitives (PDFDocument, page.drawText, page.drawRectangle, page.drawLine, and PDFCheckBox / PDFTextField AcroForms) using a bottom-left Cartesian origin. CodePDF's WASM layout compiler flips top-left canvas coordinates, wraps multiline text, draws vector tables, and wires interactive form widgets automatically.
- Automatically converts top-left visual designs into exact bottom-left pdf-lib (x, y) coordinates
- Generates multi-column tables, word-wrapped paragraphs, and dynamic flow cursor shifts without external table plugins
- Natively compiles interactive AcroForm fields (form.createTextField, form.createCheckBox, form.createDropdown) and @pdf-lib/fontkit custom fonts
Quick Start: Generate PDFs with pdf-lib
Install pdf-lib (TypeScript / JS), then run the code CodePDF exports for any template:
npm install pdf-lib@^1.17.1 @pdf-lib/fontkit
- Save the generated file as MyDocument.ts and import the exported build function.
- Run it with tsx MyDocument.ts (or compile with tsc first).
- Write the returned bytes to disk: fs.writeFileSync('out.pdf', bytes).
- Register fontkit and embed custom TTF/OTF bytes with pdfDoc.embedFont(bytes).
Example pdf-lib Output (Standard B2B Commercial Invoice)
Compiled directly from the Standard B2B Commercial Invoice template (TypeScript / JS):
import { PDFDocument, StandardFonts, rgb, PDFPage, PDFString, Color } from 'pdf-lib';
// This code is generated using codepdf.dev
export interface DocumentData {
vendorCompany: string;
invoiceNumber: string;
vendorAddress: string;
invoiceDate: string;
paymentDueDate: string;
grandTotalNum: number;
clientCompany: string;
clientDetails: string;
lineItems: Array<Record<string, any>>;
wireBank: string;
paymentTerms: string;
subtotalAmount: string;
taxAmount: string;
grandTotal: string;
paymentMethods: string[];
}
export const SAMPLE_DATA: DocumentData = {
vendorCompany: 'MERIDIAN CLOUD INFRASTRUCTURE LLC',
invoiceNumber: 'INV-2026-8842',
vendorAddress: '100 Montgomery St, Suite 2400, San Francisco, CA 94104 · EIN: 84-2938192',
invoiceDate: '12 Sep 2026',
paymentDueDate: '12 Oct 2026 (Net 30)',
grandTotalNum: 26674.38,
clientCompany: 'Apex Global Enterprises Inc.',
// … (522 more lines in full generated file)
Custom Fonts in pdf-lib
Generated standalone code defaults to Standard 14 fonts (Helvetica/Times/Courier); attach @pdf-lib/fontkit to your PDFDocument instance before embedding custom TTF or OTF font bytes.
- Install @pdf-lib/fontkit alongside pdf-lib.
- Call pdfDoc.registerFontkit(fontkit) immediately after PDFDocument.create().
- Load TTF/OTF bytes from disk or fetch() and pass them to await pdfDoc.embedFont(fontBytes).
Official documentation: pdf-lib docs
pdf-lib Benchmark Results
Measured on CodePDF’s 26-component, 20-page All-Components Dynamic Multi-Page Flow Stress Test (same document across all 22 libraries).
| Metric | pdf-lib | Rank (of 22) |
|---|---|---|
| Wall-clock time | 334 ms | 13th fastest |
| CPU time | 1.09 s | 15th lowest |
| Peak RAM | 209.7 MB | 20th lowest |
| PDF file size | 203.8 KB | 17th smallest |
- Engine type
- Low-Level / Object Editor
- Under the hood
- Pure JS/TS PDF 1.7 object & content-stream builder with zero native binaries
- Runs in
- Browser, Node.js, Deno, Bun, Cloudflare Workers
- Verdict
- Runs in browsers & Edge Workers and edits/merges existing PDFs (5.3 ms single-page; 334 ms / 203.8 KB across 20p).
Under the Hood & Benchmark Highlights
- One of the few JavaScript libraries that can both create PDFs from scratch AND load, modify, merge, or fill interactive AcroForms in existing PDFs.
- 100% pure JavaScript with zero native bindings or browser requirement — runs identically in Cloudflare Workers, Deno, Bun, Node.js, and browsers.
- Completed our 11-page 26-component stress test in 1.60s (169.4 KB PDF, ~214 MB RAM) using pre-computed coordinates and cursor-shift helpers.
Good to Know (pdf-lib Caveats)
- Coordinate-based engine: pdf-lib has no built-in Flexbox, HTML, or table layout engine; CodePDF emits coordinate math, text-wrapping, and vertical flow-shift helpers.
- Unicode & custom fonts: Built-in StandardFonts only support WinAnsi encoding. Install @pdf-lib/fontkit and call pdfDoc.embedFont(ttfBytes) for UTF-8 or custom fonts.
- Low-level editing: Ideal when you also need to merge pages, stamp watermarks, or fill existing PDF forms in the same script.
Popular pdf-lib PDF Templates
- Standard B2B Commercial Invoice pdf-lib template — Enterprise commercial tax invoice with QR payment link, Currency balance KPIs, line-item ledger, and ACH wire instructions.
- Certificate of Completion pdf-lib template — Landscape certificate with decorative border, recipient name and signatures.
- Patient Medical History & Intake Record pdf-lib template — Interactive new-patient clinical intake form using fillable text field inputs, allergy pills, review-of-systems checkboxes, and HIPAA consent.
- General Liability Waiver & Release Form pdf-lib template — Assumption-of-risk and hold-harmless release form with interactive participant fields, medical consent checkboxes, and signature.
- Payment Receipt pdf-lib template — Clean transaction receipt with payment method details, item breakdown and verified badge.
- University Graduation Degree Diploma pdf-lib template — Ceremonial landscape university diploma with double navy-and-gold borders, honors pills, QR CeDiploma verification, and dual signatures.
All 100 CodePDF templates export to pdf-lib. Browse them by category: Career (5) · Business (6) · Education (7) · Marketing (6) · Human Resources (8) · Finance (7) · Legal (8) · Healthcare (10) · Logistics (6) · Real Estate (6) · Hospitality (4) · Operations (5) · Technology (5) · Banking (9) · Non-Profit (4) · Personal (3) · Compliance & Enterprise (1), or see the full template gallery.
pdf-lib Template FAQs
Does pdf-lib support tables and automatic text wrapping?
Out of the box, pdf-lib only provides low-level drawText() and drawRectangle() calls. CodePDF's pdf-lib generator emits self-contained text-wrapping, table header/row rendering, and runtime vertical flow-shift helpers with zero extra npm dependencies.
Can pdf-lib templates run on Cloudflare Workers and Edge runtimes?
Yes. Because pdf-lib is pure JavaScript/TypeScript with zero native C++ binaries or DOM dependencies, code exported by CodePDF runs natively in Cloudflare Workers, Vercel Edge Functions, Deno, Bun, Node.js, and browsers.
Does CodePDF generate interactive fillable PDF forms for pdf-lib?
Yes. Templates using FormTextField, Checkbox, RadioButton, and Dropdown components compile directly to pdfDoc.getForm() AcroForm widgets in pdf-lib.
pdf-lib vs Other Node.js PDF Libraries
- @react-pdf/renderer — 1.06 s, 237.3 MB RAM, 126.8 KB PDF. #2 smallest multi-page PDF overall (126.8 KB across 18p; 12 ms single-page, 1.06s stress) with Yoga Flexbox; run server-side in Next.js.
- jsPDF — 120 ms, 98.3 MB RAM, 157.4 KB PDF. Fastest Node.js/browser JS engine in stress test (120 ms for 22p, 3.5 ms single-page, 98.3 MB RAM); custom TTFs require base64 VFS.
- pdfmake — 189 ms, 183.7 MB RAM, 165.5 KB PDF. Declarative JSON tables & automatic pagination in 189 ms (27p, 165.5 KB; 4.4 ms single-page); VFS fonts add weight to browser bundles.
- PDFKit (Node.js) — 140 ms, 125.5 MB RAM, 162.6 KB PDF. Fastest server-only Node.js stream writer on single-page invoices (2.8 ms / 2.6 KB; 140 ms / 125.5 MB RAM across 22p).
- Puppeteer — 1.35 s, 263.2 MB RAM, 841.2 KB PDF. Full Chrome CSS fidelity, but 841.2 KB PDF (#2 largest), 263.2 MB RAM (highest), 1.35s warm render (+ cold Chrome launch & ~350 MB binary).
- Playwright — 883 ms, 203.8 MB RAM, 452.2 KB PDF. Beat Puppeteer on pure PDF render speed (883 ms vs 1.35s), RAM (204 vs 263 MB), and PDF size (452 vs 841 KB); Chromium-only.
- HTML5 & CSS Paged Media — 818 ms, 196.3 MB RAM, 453.6 KB PDF. Renderer-agnostic HTML5 + @page CSS; warm Chromium print finishes 19 pages in 818 ms (453.6 KB; 581 ms single-page).
See the full 22-library benchmark rankings · Compare all supported PDF libraries