Best Solution For Generating PDF Documents From Templates - R - Node
Best Solution For Generating PDF Documents From Templates - R - Node
Best Solution For Generating PDF Documents From Templates - R - Node
The problem being I have multiple tenants and need to make the templates reasonably easy to edit/create.
Currently I'm doing this via pug > html > puppeteer , however puppeteer doesn't seem stable or reliable
enough for my needs, and document generation times are in the 10s of seconds.
I've been playing with PDFMake and jsPDF, however both of these make it very difficult to design templates in
a reasonable format.
I've also toyed with JSReports, Gotenburg and Wkhtmltopdf and found all of them pretty awful.
If I was working on Windows I'd use Crystal Reports, as the document generation is extremely flexible and easy
to edit however the platform is running in docker
Read more
36 61 Share
Add a Comment
BehindTheMath • 1y ago
The best solution I have is to run Puppeteer in a GCP Cloud Function. If it's a warm start, it only takes
around 5 seconds for a 1 page PDF.
12 Reply
3 more replies
https://pdfkit.org/ is pretty powerful, surprised to see no one has mentioned this so far.
There’s also https://react-pdf.org/ if you want to write React templates for the same thing.
12 Reply
ptmdevncoder • 1y ago
I was going through the comments just to make sure that someone has mentioned about PDFKit. As
you mentioned, it is powerful.
Skip to main4 content Reply
Log In
3 more replies
[deleted] • 1y ago
I've found that a surprising number of companies simply expect you to Print > Save to PDF. It's just not
worth the time for them to actually generate a PDF.
6 Reply
ben_db OP • 1y ago
I thought about embedding in an HTML email but that doesn't work well from what I've seen.
8 Reply
2 more replies
jercs123 • 1y ago
Also, I think is not necesaary to render that thing client side with puppeter.
3 Reply
I'm struggling with your question; Is the problem flexibility of the templates? Or potential throughput?
What was the issue/are the issues with the other tools you mentioned?
If I were doing this now I'd probably just call wkhtmltopdf from cli via child_process.exec, or pass the c++
library through node-gyp for a node addon.
Do you also have to have these stored in PDF, or could you store them as html then do the conversion at
the edge when downloading/accessing them?
I use the puppeteer method for my cv; it runs in a container in CI and suits my needs because it doesn't
have to be high throughput.
Oh, another idea: can you batch this? The overhead in the puppeteer method is the browser warm up (i
think). Could you start the process, run through batches of a bunch of invoices and then tune the batch
size?
3 Reply
2 more replies
Skip[deleted]
to main •content
1y ago
Log In
Pleasant-Fish7370 • 1y ago
3 Reply
yrocrepooc • 1y ago
I thought about building this myself at one point and then found this: https://pdfgeneratorapi.com/
2 Reply
ben_db OP • 1y ago
This is reasonably expensive compared to the other options, and I don't understand how I could allow
tenants to edit the templates.
1 Reply
2 more replies
lnplum • 1y ago
There's no good solution. This isn't even a node issue: between node, python and PHP the best solution is
an extremely expensive python library. All the other options are various levels of bad.
We generate PDFs in two ways, for two different purposes: for the first use case we use PDFKit because we
have a static PDF template into which we inject text at predetermined positions. We have a metadata file
per template to indicate the positions at which the text should be injected and then try to do font size
arithmetic to figure out how to place wrapped text and such. It's messy but it mostly does the trick and
we're fairly flexible because the customer can just give us the empty PDF with their own design.
For the second use case we use a headless chromium browser. The input is highly dynamic so we
generate HTML and pray the page layouts don't break randomly. It's great at placing images and page
breaks usually work out somewhat but you'll see weird bugs like empty trailing pages you can't do
anything about. Also paged media CSS is still barely supported so most of the stuff in the spec that
sounds useful doesn't actually work.
2 Reply
1 more reply
cjthomp • 1y ago
pdfmake
1 Reply
3 more replies
800 pages PDF takes about 15-40 seconds to build on 2010 computer depending on a task. Afraid to see
the speeds of a modern 2-3 years old computer.
1 Reply
darkodelta • 1y ago
1 Reply
ben_db OP • 1y ago
4 Reply
PlNG • 1y ago
Perhaps what you're looking for is something called mail merge? Basically you take a database and a form
(be it letter, invoice, etc) and you populate the form with the data from the database.
Your existing office tool platforms may already support this function, you just need to figure out how to
connect the two.
1 Reply
goodboyscout • 1y ago
How large are these documents that are taking 10s? Does this 10s include time required to retrieve data
from a database? How long does it take to create a PDF from an existing html file generated with pug?
1 Reply
2 more replies
r/node
r/node
Express.js in 2024?
102 upvotes · 76 comments
r/BusinessIntelligence
Skip to main content
Log In
Another day and another text to SQL GPT tool is launched.
47 upvotes · 31 comments
r/TechSEO
r/node
r/Workflowy
r/node
r/reactjs
If you know React, do you automatically know React Native? What are the key differences?
131 upvotes · 64 comments
r/Musescore
r/reactjs
r/django
I've built a fully functional web application with Django + htmx + Alpine.js
113 upvotes · 48 comments
r/reactjs
r/django
r/reactjs
r/Database
[Question] Can you recommend a free ACID-compliant, scalable, highly available NoSQL database with a
search engine
15 comments
r/reactjs
r/sqlite
r/reactjs
r/reactjs
Failed a junior take-home task. Anyone want to redo it with me to show me how it's done?
253 upvotes · 194 comments
r/reactjs
r/Wordpress
Frontity + Wordpress: Is this the best way to create a website with blogging and custom app capabilities?
Log In
3 upvotes · 5 comments
r/reactjs
r/reactjs
r/reactjs
TOP POSTS