Nothing Special   »   [go: up one dir, main page]

Best Solution For Generating PDF Documents From Templates - R - Node

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Skip to main content

r/node Search in r/node Log In

r/node • 1 yr. ago


ben_db

Best solution for generating pdf documents from templates


I'm having a nightmare with software for generating invoice documents for a platform I'm developing.

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

Sort by: Best Search Comments

BehindTheMath • 1y ago

We're having the exact same issue.

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

TheCommentAppraiser • 1y ago • Edited 1y ago

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

Stepping back. Do you actually need PDF generation?

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

They need to be emailed so pdf is the standard for this.

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

Is markdown a reasonable format? https://www.npmjs.com/package/markdown-pdf

Also, I think is not necesaary to render that thing client side with puppeter.

3 Reply

jamescodesthings • 1y ago • Edited 1y ago

"is there a silver bullet?"

No. PDF is a bit of a proprietary nightmare.

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

We use https://gotenberg.dev/ with handlebars templates.

3 Reply

yrocrepooc • 1y ago

I thought about building this myself at one point and then found this: https://pdfgeneratorapi.com/

does that cover your use case?

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

Content-Egg3573 • 2mo ago


I use pdftk and PDF::API2 to build PDFs from scratch and based on templates. Yes, I know, still using Perl
Skip to main content
which is quite versatile to do/build stuff. Log In

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

Have you considered pdf-tools.com?

1 Reply

ben_db OP • 1y ago

The "contact us for pricing" makes me think it's out of my budget.

Not keen on handing my details to a pushy sales rep.

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

View more comments

More posts you may like

r/node

Best approach to generate PDF from dynamic data?


44 upvotes · 39 comments

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

How to reduce Initial server response time?


4 upvotes · 20 comments

r/node

Did anyone work with '.sex' files


186 upvotes · 65 comments

r/Workflowy

Benefits of templates over just duplicating a node?


2 upvotes · 8 comments

r/node

when you promoted to senior programmer

473 upvotes · 38 comments

r/reactjs

If you know React, do you automatically know React Native? What are the key differences?
131 upvotes · 64 comments

r/Musescore

How to convert a pdf into a MuseScore file


6 upvotes · 18 comments

r/reactjs

API key - How do you "actually" secure it?


316 upvotes · 133 comments

r/django

I've built a fully functional web application with Django + htmx + Alpine.js
113 upvotes · 48 comments

r/reactjs

Failed technical interview task, where did I go wrong?


198 upvotes · 177 comments
r/reactjs
Skip to main content
Log In
Why is react-aria not talked about as much as shadcn/radix-ui and headless ui?
158 upvotes · 45 comments

r/django

PSA: Don't forget to set up all available firewalls!


121 upvotes · 20 comments

r/reactjs

Why React Query?


ui

410 upvotes · 92 comments

r/Database

[Question] Can you recommend a free ACID-compliant, scalable, highly available NoSQL database with a
search engine
15 comments

r/reactjs

Introducing React Compiler – React


react

241 upvotes · 43 comments

r/sqlite

Is SQLite the best choice?


5 upvotes · 11 comments

r/reactjs

2-10x Speed Boost for Zustand


github

126 upvotes · 52 comments

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

Why choose Zustand over Jotai?


109 upvotes · 74 comments

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

Why don't more people use Mantine?


171 upvotes · 121 comments

r/reactjs

I am launching the most complete Icon component so far


90 upvotes · 32 comments

r/reactjs

My recent experience in a technical interview.


393 upvotes · 292 comments

TOP POSTS

Reddit

reReddit: Top posts of March 27, 2023

Reddit

reReddit: Top posts of March 2023

Reddit

reReddit: Top posts of 2023

You might also like