XML : I am looking for an Java based way to generate PDF reports, Apache FOP? PdfBox? PdfKit with Nashorn/AvatarJS?

I can't use iText or Flying Saucer (because of iText) for legal reasons I am limited to MIT, Apache Licence, GPL and LGPL (kinda but prefer if it isn't LGPL)

I know that there is a version of iText that is running LGPL and that is also what FlyingSaucer is using but yeah. Legal decided against it still, so w/e We currently have our own PDF generator that we built in house, which is pretty great. However supporting CJK (Chinese, Japanese and Korean) is not easy for us to do with how we wrote it.

So, I am learning what is out there and what options we have!

I have looked at a few things.

I was first thinking that I could possibly use PdfKit, which is a Javascript based PDF generator that works great. With that I could use PdfMake (which is built on PdfKit) and that would do everything. I was going to use javax.script stuff to run the Javasctipt code in Java and go from there. I THINK this would work. I got some basic NPM modules working in my Java Code and was looking at the Avatar.js project. Seems like a decent way to do it but I don't know how easy it will be for me to get the PDF data out of the JavaScript after I generate the File. I haven't gone too deep down that path because I wanted to look into some more... "Normal" methods.

My next idea was using PdfBox, this would work for sure but I would rather write my PDF templates in Json or Xml and not in pure Java. I considered the possibility of building a wrapper around PdfBox that could accept JSON or Handlebars code and then generate the results but that is a pretty big project. It would be kinda fun though!

Finally, I found this XSL-FO thing. As far as I can tell, FO is it's own "xml" language. I can write XSL and XML and translate it into a .fo file using Apache-FOP

I haven't gotten super far in this route, I am having a little bit of a hard time understanding their docs to be completely honest. I am normally decent at reading Docs but I am not familiar enough with XSL and FO to easily connect everything in my mind.

HOWEVER, as of right now I am thinking I will probably try the Apache-FOP and XSL-FO stuff unless there is a better solution out there!

So! My question is this: What would you recommend?

I am going down the FOP rabbit hole right now but maybe that's a bad idea?

If I can get that Node Module to run in Java would getting the PDF file out of the JavaScript Engine be possible?

Is it better to just stick with a pure Java based solution like PdfBox?

Requirements: I need to be able to display CJK fonts, tables with repeating headers on page breaks, and images. I don't need anything too fancy beyond that, but if I can get CSS3 amazingness then I would gladly take it!

As far as I can tell, all those things (except css) are possible with the things I have listed here.

I would love to hear what you all think!

No comments:

Post a Comment