Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: TinyPDF – 3kb pdf library (70x smaller than jsPDF) (github.com/lulzx)
95 points by lulzx 5 hours ago | hide | past | favorite | 12 comments
I needed to generate invoices in a Node.js app. jsPDF is 229KB. I only needed text, rectangles, lines, and JPEG images.

  So I wrote tinypdf: <400 lines of TypeScript, zero dependencies, 3.3KB minified+gzipped.

  What it does:
  - Text (Helvetica, colors, alignment)
  - Rectangles and lines
  - JPEG images
  - Multiple pages, custom sizes

  What it doesn't do:
  - Custom fonts, PNG/SVG, forms, encryption, HTML-to-PDF

  That's it. The 95% use case for invoices, receipts, reports, tickets, and labels.

  GitHub: https://github.com/Lulzx/tinypdf
  npm: npm install tinypdf




It's definitely far easier to emit a controlled, useful subset of PDF than it is to parse PDF documents. I wrote a small PDF library for the Decker ecosystem that just focuses on bitmaps and page layout; roughly 4kb and 135 LoC.

docs/demos: https://beyondloom.com/decker/pdf.html

browsable source: https://github.com/JohnEarnest/Decker/blob/main/examples/dec...


Back in the day I needed PDF export for some client thing. I can't remember if I was using pdfjs or jspdf. I do however remember that it was many thousands of lines of code, and yet, I had to lay out the lines of text on the page manually.

My page layout code was like 50 lines of code. And I remember thinking... OK they already wrote 8,000 lines of code... They couldn't have added 50 more?!

400 lines though. Respect. I will take a proper look at this when I recover from burnout :)


Great exercize, but for most use cases - people will continue reaching for jsPDF.

I think if you have a markdown->PDF function included, where I can send in markdown and get PDF, that would solve quite many needs, and would be useful.


I have added it!


So essentially - it only works with Latin script? Because without fonts, every other script is NOT going to render.

3KB is wild. What features did you intentionally leave out to get this small?

Not the author, but generating PDFs is much, much simpler than parsing PDFs

It only supports Helvetica!

Support for more than 7-bit ASCII characters. :)

is it related to one of the other 10 products called TinyPDF?

Yes, obviously: it's a tiny PDF library.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: