5 ms·
I was wondering if I could use this (using a plugin) or Chrome to generate PDF files on the web server. Most of the PDF generation software out there are quite
by arunitc 9y ago
I was wondering if I could use this (using a plugin) or Chrome to generate PDF files on the web server. Most of the PDF generation software out there are quite expensive.
- boredpudding 9y agoMaybe it's possible with the print option Chrome offers. Regular Chrome can print to PDF files. Maybe headless Chrome supports that. Edit: It's possible. It's on the introduction page of Chrome Headless https://developers.google.com/web/updates/2017/04/headless-chrome https://developers.google.com/web/updates/2017/04/headless-c... Look at 'Create a PDF'
- robk 9y agoHere's a simple library to do that: https://github.com/LucianoGanga/simple-headless-chrome https://github.com/LucianoGanga/simple-headless-chrome
- mchiron 9y agoWe use wkhtmltopdf to do this server side. It as a few problems and quirks, but it work well enough for us.
- pilif 9y agoit has a lot of quirks, and, frankly, webkit is pretty bad at printing in general as it lacks a ton of printing specific features like re-printing table headers across page boundaries. There's also only very rudimentary support for page headers and footers. wkhtmktopdf is probably ok if you just need a quick single page invoice printout, but the moment you need more (in our case, we definitely do), I can highly recommend paying for https://www.princexml.com/ https://www.princexml.com/ which has support for a lot of printing specific features.
- veza 9y agowkhtmltopdf works quite well for us, even with modern web technologies. Here's an example fully rendered in React: https://s3.amazonaws.com/ud-reports/comps-report-86.pdf https://s3.amazonaws.com/ud-reports/comps-report-86.pdf And one with svg charts: https://s3.amazonaws.com/ud-reports/chart-report-89.pdf https://s3.amazonaws.com/ud-reports/chart-report-89.pdf With -webkit- prefixes you can use even flexbox, and and with js polyfills you'll have all you need. Of course if I would start a project now, I would use chrome headless, but I don't feel wkhtmltopdf is that bad.
- bowersbros 9y agoOne of the issues we had with wkhtmltopdf was that we use Angular for our views, and we have a view for an invoice, and the ability to print it. We wanted the same view to be passed into wkhtmltopdf to download it as PDF (with a couple of things omitted). Unfortunately, the JS didn't execute properly, so you get a borked output. End result was we render it, capture the HTML after render, and pipe that through to wkhtmltopdf. Using chrome _should_ resolve that issue and let us just pass the page through.
- mhb 9y agoWhat about ReportLab (free version)? http://www.reportlab.com/opensource/ http://www.reportlab.com/opensource/
- aidos 9y agoYou can. In my experience, there are very few systems as good at producing accurate renders as well as Chrome. There are a few Chrome/webkit based options. PhantomJS made the process pretty easy, but that's probably not a good option these days as it's on the way out. NightmareJS is pretty much the same and can do it (though I haven't tested myself) [0] If you want to get a little deeper you can use CEF (Chromium Embedded Framework [1 ]. It basically turns Chrome into a library and there are a bunch of projects that build on top of it (eg Electron, which is what NightmareJS uses underneath). Here's a project that just uses CEF for converting to PDF [2]. [0] https://github.com/segmentio/nightmare#pdfpath-options https://github.com/segmentio/nightmare#pdfpath-options [1] https://bitbucket.org/chromiumembedded/cef/overview https://bitbucket.org/chromiumembedded/cef/overview [2] https://github.com/spajak/cef-pdf https://github.com/spajak/cef-pdf
- RandomBookmarks 9y agoFor C#, there is also CEFSharp. This is used, for example, by the image(recognition)-driven Kantu automation: https://a9t9.com/kantu/web-automation https://a9t9.com/kantu/web-automation
- gjjrfcbugxbhf 9y agoLatex is free.
- JBorrow 9y agoReally not the same thing (e.g. pandoc for html -> pdf via LaTeX) as having a webkit based renderer. They do not look the same at all; sometimes it is good to have a LaTeX output but most of the time you are going to want a more accurate representation of your HTML.
- majewsky 9y agoThe original question didn't state that he was starting from HTML. If you want to generate an invoice or such from plain data, then LaTeX seems like a good fit. Rendering HTML is a whole different bag.
- tremon 9y agoThat is true. TeX is a typesetting engine, and allows you exact control over the final rendering, while HTML is a markup language, the rendering of which depends on very many factors.
- criddell 9y agoMy time isn't. Sometimes the most cost effective option isn't the one with the lowest price tag.
- chronic7ul 9y agoPerhaps you need a larger budget. Time and money.
- 0XAFFE 9y agoWe used node-html-pdf[1] for this, but it depends on phantomjs which uses an ancient version of webkit. We migrated to electron and its contents.printToPDF(options, callback), but that has the drawback that we have to start a X-server[2] with our backend code. I have hopes with a headless chrome we can ditch the xvfb-server and have one less dependencies. The setup is a pain, but the results are very good and looking very decent. [1] https://github.com/marcbachmann/node-html-pdf https://github.com/marcbachmann/node-html-pdf [2] https://en.wikipedia.org/wiki/Xvfb https://en.wikipedia.org/wiki/Xvfb
- wnevets 9y agoI currently use phantomjs for this, I haven't switched to headless chrome yet.