7

I've been searching high and low for an up to date solution to this age old problem.

Long story short I want to take css + html -> pdf and do it in java.

I don't want to use an API as the data is sensitive. Googling provides me with countless sites/services that offer to do this but I'm looking for a stand alone tool and looking for one that will work nicely from my java server. I've found this awesome looking command line tool but it's a command line tool and spawning processes off a web server starts to get sketchy IMO (but I'm always willing to hear otherwise). Additionally flying saucer seems to be a standard choice, but I've heard mixed reviews.

Here is a 5 year old question on the subject, but I figure things have changed! Especially with all the work being done in the area of front end unit testing with dom manipulation I figure there might be some less than conventional solutions and I'm willing to hear them all!

Any help would be greatly appreciated.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
matty-d
  • 2,623
  • 3
  • 18
  • 21
  • 2
    I have been working with Flying Saucer for some years now. While it does the job it often fails with various impossible to understand errors. It is highly sensitive and accepts only 100% valid strict XHTML. Be aware that it is no longer maintained! IMO it is way to sensitive/error prone and I am looking for an alternative like you - no luck so far :( – Hoof Jul 17 '14 at 10:12
  • I am looking at the answer of this question http://stackoverflow.com/questions/25574082/how-to-use-the-browsers-chrome-firefox-html-css-js-rendering-engine-to-produc it will help to anything related to html->pdf – David Hofmann Aug 29 '14 at 18:31
  • You might try phantomjs, as described here: https://stackoverflow.com/a/37173011/1251543 – cobbzilla May 11 '16 at 21:16

1 Answers1

2

You might try a combination CSSBox that converts HTML+CSS to SVG and then use for example Batik for creating your PDF as proposed for example here. FlyingSaucer could also do the job.

The choice depends on your further requirements. E.g. are you processing "street HTML" or well-formed documents? What about the pages in the resulting PDF? What about interactive elements in the HTML pages?

I mean the only way is to try at least some options practically and then you may ask more specific questions about some particular problems.

Community
  • 1
  • 1
radkovo
  • 868
  • 6
  • 10