Skip to content

Repository files navigation

Universal PDF

Production-ready TypeScript PDF generation library focused on image-to-PDF conversion and template-based PDF generation.

Features (Phase 1)

  • Image to PDF conversion (PNG, JPG/JPEG, WEBP)
  • Multiple images to single PDF
  • Multiple PDFs from multiple images
  • JSON template system with variables, conditionals, and repeaters
  • Preset templates: invoice, certificate, resume, report
  • Custom fonts, watermarks, headers/footers hooks, metadata
  • Browser and Node.js support
  • ESM + CJS dual builds with tree-shaking

Monorepo Structure

packages/
  core/         # Document, page, export, plugin engines
  image/        # Image-to-PDF engine
  template/     # Template rendering engine
  fonts/        # Custom font loading
  watermark/    # Watermark utilities
  metadata/     # Metadata builder
  browser/      # Browser adapter + PDF.js viewer layer
  node/         # Node.js adapter
  shared/       # Shared types and errors
  utils/        # Shared utilities
apps/
  docs/         # TypeDoc documentation site
examples/
  image-to-pdf/
  invoice-template/
  certificate-template/

See ARCHITECTURE.md for full design details.

Install

pnpm add @universal-pdf/node
# or
pnpm add @universal-pdf/browser

Quick Start

Image to PDF (Node.js)

import { createPdfFromImages, readImageFile, savePdfToFile } from '@universal-pdf/node';

const images = [await readImageFile('./photo.png')];
const pdf = await createPdfFromImages({
  images,
  fit: 'contain',
  size: 'A4',
  metadata: { title: 'Photo Album' },
});

await savePdfToFile(pdf, './output.pdf');

Template PDF

import { createPdfFromTemplate, savePdfToFile } from '@universal-pdf/node';
import { invoiceTemplate } from '@universal-pdf/template/presets';

const pdf = await createPdfFromTemplate({
  template: invoiceTemplate,
  data: {
    invoiceNumber: 'INV-001',
    customerName: 'Acme Corp',
    issuedAt: '2026-06-07',
    total: '$500.00',
    lineItems: [
      { description: 'Design', quantity: 1, amount: '$500.00' },
    ],
  },
});

await savePdfToFile(pdf, './invoice.pdf');

Core API

import { createPdf } from '@universal-pdf/core';

const doc = await createPdf({ metadata: { title: 'Hello' } });
doc.addPage({ size: 'A4' });
await doc.addText('Universal PDF');
const bytes = await doc.toBuffer();

Development

pnpm install
pnpm build
pnpm test
pnpm docs

License

MIT

About

Production-ready TypeScript PDF generation library focused on image-to-PDF conversion and template-based PDF generation.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages