What’s everyone using to create PDFs these days? O...
# cfml-general
d
What’s everyone using to create PDFs these days? Our setup is generally a Lucee back-end using Coldbox, React front-end, all using one codebase via cbelixir. Besides react, we use Highcharts as a charting engine too. Generally, we have some views that we’d like to just create printable/PDF versions of. We have less of a requirement to create crazy specific PDFs where there is no related webpage/view, if that makes sense. Because of all that, cfdocument doesn’t seem like a great way to go. Thoughts? Is wkhtmltopdf the best route? If so, anyone using it with React/Lucee?
s
Yes (though Vue, not React) - https://forgebox.io/view/wkhtmltopdf in Coldbox talks to a wkhtmltopdf container we run on our production swarm
I don't know that Vue really interacts with it - we just produce the PDFs through our API and send them to the client
d
So do you have any Vue pages that you just want to make a printer-friendly version of? If so, do you create two totally separate views in those cases then? (the Vue.js view and the PDF?)
s
We haven't really had that use case. We're producing specific documents to be printed when we're using wkhtmltopdf rather than using it for printer-friendly web pages
d
Ah, gotcha. We have some of that, but less of it than the printer-friendly web pages probably.
a
We're working on using https://playwright.dev/docs/cli#generate-pdf to do it
🙌 1
s
there is also a java library if you want to use it inside your code for playwright here is a task brad helped me write https://gist.github.com/bdw429s/12cf16ae1d232688466897d8d073ec54
c
@danmurphy Possibly a silly question, but for "printer-friendly web pages" why don't you just add
@media print{}
to your CSS?
👍 1
d
I second @cfsimplicity's suggestion. Converting web pages to PDF does not by itself make them print-friendly. CSS gives you the tools to handle page breaks, page margins, different paper sizes, headers, footers, page numbering, etc.. I don't know if the PDF format really adds anything to that (other than additional complexity and resource usage).
s
possibly the only other thing would be convenience and consistency. Not all browsers support the same print styles, especially when it comes to page numbering and breaks and such. Secondly many businesses expect a pdf first approach and although many browsers do support print-to-pdf
👍 1
d
@Scott Steinbeck I know browser support for the paged media CSS standards used to be very spotty, but the situation seemed to be improving last time I looked into it. Sounds like maybe it's still not quite there yet? Most PDF converters (including wkhtmltopdf) also had poor support for the print-related standards back when I used to work on this kind of stuff. The only one that had full support was a commercial product called Prince (which appears to still be around). But that was quite a few years ago, so there may be other/better options now.
d
@cfsimplicity not a silly question at all. And the answer? Not sure. Ignorance? 😄 I’ve never used it. Off to Google land!
I really appreciate everyone’s thoughts so far.
d
@danmurphy In addition to
@media print
, you'll probably also want to look up the CSS "`@page` rule" and
page-break-
properties. Particularly, look into browser support for those things.
d
Thanks folks - we made some changes using the
@media print {}
stuff yesterday and that seemed to work pretty well. It feels like we might have two workflows. 1 - print friendly web pages 2 - reports that are printed from the server via jobs and such