Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pdf-generator

npm install @ferrow/pdf-generator

CI

A minimal text-and-lines PDF writer, built from scratch — no bindings, no embedded binaries, zero dependencies. It emits valid PDF 1.4 byte-for-byte: catalog, pages, page, font, and content-stream objects, an exact xref table (byte offsets computed while writing, not estimated), and a trailer.

What this is

  • Multi-page documents (addPage()).
  • Text placement at (x, y) with a size, using the core Helvetica font (no font embedding — Helvetica is one of the 14 standard PDF fonts every reader already has).
  • Straight lines (line(x1, y1, x2, y2)).
  • mm() / pt() unit helpers (PDF's native unit is points; 1mm = 72/25.4pt).
  • Correct xref offsets, verified by file reporting a valid PDF document, version 1.4, N pages and by startxref pointing at the real xref byte.

What this is NOT

  • No images, no embedded/custom fonts, no Unicode (Helvetica + WinAnsi-range text only — escapes \, (, ); does not transcode wide characters).
  • No compression, encryption, forms, or annotations.
  • Not a layout engine — no word wrap, no flow, you place text and lines by coordinate. For anything beyond plain text-and-lines, use pdfkit or pdf-lib.

Quickstart

npm install
npm run build
node dist/examples/demo.js

API

import { PdfDocument, mm } from 'pdf-generator';

const doc = new PdfDocument(); // defaults to A4; pass { pageSize } for Letter, etc.

const page = doc.addPage();
page.text(mm(20), page.size.height - mm(20), 'Hello, PDF', { size: 18 });
page.line(mm(20), page.size.height - mm(25), mm(190), page.size.height - mm(25));

const buffer = doc.toBuffer(); // Node Buffer, valid PDF 1.4
require('fs').writeFileSync('out.pdf', buffer);

Coordinates are in points with the PDF-native origin at the page's bottom-left corner (not top-left).

Demo

examples/demo.ts generates a 2-page PDF and verifies the output:

$ node dist/examples/demo.js
header: %PDF-1.4
size: 985 bytes
contains text: true

$ file dist/examples/demo-output.pdf
dist/examples/demo-output.pdf: PDF document, version 1.4, 2 pages

License

MIT


Sponsored by Ferrow


Part of the ferrow-toolkit collection · Sponsored by Ferrow

About

Minimal text-and-lines PDF 1.4 writer built from scratch, zero dependencies. Helvetica core font, multi-page, mm/pt units.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages