4

I'm currently considering using xsl-fo/fop to generate PDFs out of my Java web application. Parts of the content to be printed are "HTML fragments" (TinyMCE editor in web frontend) from different sources.

Is there a way to "embed" HTML into FOP?

I want to avoid an xslt transformation for individual paragraphs containing HTML fragments (the doc contains a lot of other content as well). The alternative is to create one HTML/XML document containing all the paragraphs and other content and then apply an xslt transformation over everything, but somehow I'd like to avoid this if possible.

Note: I also considered HTML to PDF engines (e.g. Prince) but they seem to be ludicrously expensive.

Thanks!

Thomas
  • 1,119
  • 9
  • 24
  • Have you looked at iText (java library for pdf generation)? It can convert HTML to PDF, but I have never used the feature, so don't know how good it is at that. – Matthew Feb 20 '16 at 10:58
  • 1
    Yes, looked at iText but haven't tested it. iText with its new licensing model is a bit prohibitive though. – Thomas Feb 21 '16 at 01:44
  • This is a related question I answered which contains some relevant information/pointers ... http://stackoverflow.com/questions/32789541/pdf-report-with-embedded-html/32789843#32789843 – Kevin Brown Feb 21 '16 at 18:37
  • @KevinBrown Thanks, quite useful, esp the css2pdf stylesheets mentioned. – Thomas Feb 22 '16 at 11:51

1 Answers1

3

No, FOP's only valid input is an XSL-FO file (or XML + XSLT producing XSL-FO, but that's just a convenience option as it's an external library that performs the transformation).

However, you can use / adapt an existing xhtml to FO stylesheets, like those provided by AntennaHouse and RenderX.

Besides, even if you say you don't want to do it, writing an xhtml -> XSL-FO transformation is not a daunting task; this is especially true if the input comes from TinyMCE, as you can configure it to allow only a limited subset of tags, which will require a small set of templates.

(disclosure: I'm a FOP developer, though not very active nowadays)

lfurini
  • 3,729
  • 4
  • 30
  • 48
  • Thanks for the links to the XSLT templates, I might go that way. By the way, as FOP feels a bit dated, do you have any other suggestions? Currently I'm using JasperReports but that doesn't scale well for complex documents. – Thomas Feb 21 '16 at 01:48
  • @Thomas Why do you think it is dated? It had a new release last month :-) (to clarify my disclosure: _I_ have not been very active in the latest years, other developers worked on FOP _a lot_) – lfurini Feb 21 '16 at 06:44
  • 1
    I know, but it's been around for ages (not a bad thing) and nowadays people talk a lot about HTML+CSS3. Having said that I think FOP allows a much better control over the outcome and is mature. – Thomas Feb 21 '16 at 06:55