Convert html+css+js to PDF

2019-07-19 10:59发布

问题:

I want to create something like this (code is here):

in pdf format. I'm using google charts and regarding to this forum converting chart to pdf is impossible. I've already tryied iText+XMLWorker, but there is some problem with css and any js supporting at all, I think.


So, the questions are: How can I convert html+css+js to .pdf file? Or, may be, the issue have other variants?

回答1:

As promised in the comment, I've asked Raf. This was his answer:

One way to use XML Worker for HTML+CSS+JS is to use a browser engine to preprocess the HTML. Examples of such a browser engine are WebKit (Chrome, Safari) and Gecko (Firefox). These can interpret the CSS and JS and give you HTML that is ready to be parsed by XML Worker.

Examples of competing products are:

  • wkhtmltopdf, a command line tool that uses WebKit as its rendering engine.
  • Prince XML supports HTML+CSS+JS to PDF using their own engine.

Maybe there are others, but this is what Raf told me. I hope this helps.