217 pointsby lulzx2 days ago17 comments
  • RodgerTheGreat20 hours ago
    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...

    • kuschkufan8 hours ago
      This decker stuff is pretty nifty too
    • user39393822 hours ago
      I’m working on one rn. It takes arbitrary PDFs and builds composable dynamic pandoc pipelines to match the source byte for byte output. It’s very very complex. But if I can get it finished it will fuck over Adobe so worth it.
  • culi19 hours ago
    While not quite as small as 3kb, I recently found this incredible library called html-to-image that's only 300kb. It clones whatever subtree of your document you want to a <foreignObject> inside an svg which then allows it to output canvas, png, svg, pdf, blob, jpeg, etc. Even more impressively is that it handles custom fonts, pseudo-elements, computed styles and more.

    https://github.com/bubkoo/html-to-image

    It's probably the most impressive and seamless experience I've had with converting HTML to pdfs/images so I just wanted to sing its praises here

  • layer818 hours ago
    Only supports ASCII characters, which is part of the trick here. As soon as you need more Unicode (even just typographic quote characters and such), you’ll need significantly more logic. Also no bold, italics, etc.
  • andai21 hours ago
    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 :)

    • 19 hours ago
      undefined
  • anilgulechaa day ago
    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.

  • raybb17 hours ago
    Was Typst falling short in any particular area that made you not want to use it? (If it was on your radar at all). I think it would work for your use case and could also run client side if needed.

    Here's the TS library: https://github.com/Myriad-Dreamin/typst.ts

  • copypaper15 hours ago
    Nice work! I'm curious though, what was your use case for needing a smaller library? Since you're running this on a server, what difference does an extra 226KB make?
  • wg020 hours ago
    So essentially - it only works with Latin script? Because without fonts, every other script is NOT going to render.
    • jbaiter8 hours ago
      Agree, the lack of support for TTF fonts is a bummer for most non-english use cases:-/
  • alexpadula2 hours ago
    Well ain’t that a useful 400 lines of code eh! Good work
  • 15 hours ago
    undefined
  • dzrmb8 hours ago
    I actually was battling jsPDF the other day so definitely need to give this a try, thanks!
  • nanis6 hours ago
    HTML + CSS works great for this kind of thing. Once you get the print scope correct, you really never need to think about it again.
  • userbinator13 hours ago
    I still have a tiny DOS binary (x86 Asm) that I wrote decades ago for turning plaintext ASCII files into PDFs, for those annoying use-cases where the former isn't accepted but the latter is. It's only a few hundred bytes, with the majority being data to be copied verbatim into the output file.
  • IntelliAvatar2 days ago
    3KB is wild. What features did you intentionally leave out to get this small?
    • wonger_a day ago
      Not the author, but generating PDFs is much, much simpler than parsing PDFs
    • lysace21 hours ago
      Support for more than 7-bit ASCII characters. :)
    • teaearlgraycold20 hours ago
      It only supports Helvetica!
    • hu35 hours ago
      utf-8
  • ErroneousBosh2 hours ago
    Heh, no stars when I first looked and though "hey I'll star this" and now 300 ;-)
  • winterec15 hours ago
    Great work thanks for sharing. I've been looking for something like this for generating invoice PDFs without bloat.
  • croisillona day ago
    is it related to one of the other 10 products called TinyPDF?
    • esafak21 hours ago
      Yes, obviously: it's a tiny PDF library.