foliojs / pdfkit

A JavaScript PDF generation library for Node and the browser
http://pdfkit.org/
MIT License
9.78k stars 1.14k forks source link

HTML to design PDF pages #1409

Open harsh-haria opened 1 year ago

harsh-haria commented 1 year ago

Feature Request

Able to design the pdf pages with HTML and CSS with dynamic content.

Feature description

It's hard to code the pdfs when we have a ton of dynamic data. Creating tables is necessary and surely Pdfkit provides it. However, it would be great if Pdfkit would support html syntax for the pdfs out of the box and no need to do any additional stuff. We can use plain syntax of html to structure to align the page. also adding the CSS would be cherry on top

There is a package called pdf-node which does just that. However, we don't have the option to create new page and break the content according to our will. However, I might be incorrect and missing something while providing the information, if you are aware about this stuff, please let me know. Thanks

ericyd commented 1 year ago

I'm not a maintainer but I'll chime in and note that any HTML-to-PDF library requires some form of a browser. The library you linked depends on html-pdf which depends on phantomjs. The html-pdf npm package recommends using puppeteer. Puppeteer requires a browser to power its PDF generation too.

One exception I came across recently is react-pdf. Obviously react and HTML are not interchangeable, but it might work for your purposes. react-pdf depends on pdfkit so won't require a browser installation. I failed to get react-pdf working when I tried it but I didn't try very hard.

My suspicion is that this feature request is out of scope for this project but perhaps puppeteer could work for your purposes, it is very robust and fast.

danomatic commented 5 months ago

I made react-pdf-html for this purpose

https://www.npmjs.com/package/react-pdf-html