I'm currently developing an invoicing system for my SaaS boilerplate and faced quite a struggle with PDF generation. My main goals were straightforward: I needed to take a Razorpay payment, generate a simple PDF invoice that included GST details, and then email it to the user. However, it took me three whole days to get this done. The process was so cumbersome, from styling the PDF to managing fonts and stream buffers in Server Actions, that it honestly felt more daunting than implementing the actual AI features of my app. I've wrapped all this up into my kit so I won't have to deal with it again. For anyone interested, I ended up using `react-pdf` `/ `jspdf`, as they seemed to work best with Next.js 14.
3 Answers
PDFs can be notoriously tricky because it's a really complex file format. It's difficult to create a user-friendly library around it since there's so much to consider.
One quick workaround I found is to just set up a webpage and then save it as a PDF using a headless browser. It's a simple solution that often works well for basic needs.
Have you checked out gotenberg.dev? It's a separate service that lets you convert any URL to a PDF using a headless Chrome instance via an API. We use it for generating invoices, and it works great!
That's interesting! We usually use Puppeteer for creating PDFs. Do you think Gotenberg is a better fit or just offers something different?

I totally get that! It's surprising that we still rely so much on PDFs and Word docs for professional documents.