Show HN: TinyPDF – 3kb pdf library (70x smaller than jsPDF)

https://news.ycombinator.com/rss Hits: 17
Summary

tinypdf Minimal PDF creation library. <400 LOC, zero dependencies, makes real PDFs. npm install tinypdf View sample PDF — Generated with ~50 lines of code Why tinypdf? tinypdf jsPDF Size 3.3 KB 229 KB Dependencies 0 2 ~70x smaller. We removed TTF fonts, PNG/SVG, HTML-to-PDF, forms, encryption, and compression. What's left is the 95% use case: put text and images on a page. Build with it Invoices, receipts, reports, shipping labels, tickets, certificates, contracts, data exports Features Feature Description Text Helvetica, any size, hex colors, align left/center/right Shapes Rectangles and lines Images JPEG (photos, logos, signatures) Pages Multiple pages, custom sizes Markdown Convert markdown to PDF with headers, lists, rules Not included Custom fonts, PNG/GIF/SVG, vector graphics, forms, encryption, compression, HTML-to-PDF Need those? Use jsPDF or pdf-lib. Quick start import { pdf } from 'tinypdf' import { writeFileSync } from 'fs' const doc = pdf ( ) doc . page ( ( ctx ) => { ctx . rect ( 50 , 700 , 200 , 40 , '#2563eb' ) // blue rectangle ctx . text ( 'Hello PDF!' , 60 , 712 , 24 , { color : '#ffffff' } ) ctx . line ( 50 , 680 , 250 , 680 , '#000000' , 1 ) // black line } ) writeFileSync ( 'output.pdf' , doc . build ( ) ) Add images import { readFileSync } from 'fs' doc . page ( ( ctx ) => { const logo = new Uint8Array ( readFileSync ( 'logo.jpg' ) ) ctx . image ( logo , 50 , 700 , 100 , 50 ) } ) Measure text width import { measureText } from 'tinypdf' measureText ( 'Hello' , 12 ) // => 27.34 (points) Markdown to PDF import { markdown } from 'tinypdf' import { writeFileSync } from 'fs' const pdf = markdown ( ` # Hello World A minimal PDF from markdown. ## Features - Headers (h1, h2, h3) - Bullet lists - Numbered lists - Horizontal rules --- Automatic word wrapping and pagination included. ` ) writeFileSync ( 'output.pdf' , pdf ) API pdf ( ) // create document doc . page ( callback ) // add page (612×792 default) doc . page ( width , height , callback ) // add p...

First seen: 2025-12-19 21:18

Last seen: 2025-12-20 13:28