xpages - How to output rich text (html) field content when outputting to PDF using Apache FOP -
i trying generate pdf file using xagent , apache fop suggested stephen wissel here: http://www.wissel.net/blog/d6plinks/shwl-8tnltv. of process working fine, xagent called, creates xml document , passes through transform output pdf. stuck on how handle rich text fields. fields contain user-generated content (created in xpage) , contain html fragments. has come way output rich text fields along other content pdf?
rich
richtext [insert unprintable]. there number of considerations:
- do require richtext in full client beauty (tabbed tables, ole, sections, hovers etc.)?
- is html representation of richtext enough (the 1 when @ through browser - enriched appsfidelity)?
in former case avenue grab dxl representation , try convert 1 - played that, seems feasible long , painful road.
in later case, first hands on html representation. can done using ?openfield command or code snipped mark.
now have html, might want cleanup using jsoup , convert 1 xsl:fo. guidance can found here:
- a developerworks article outlining conversion options, including sample style sheet
- a wiki article in fop wiki, pointing style sheet , tool
unfortunately not copy/paste solution, doable. let know how goes, topic seems of general interest xpages , domino.
update
transform html need convert xhtml. works this:
org.jsoup.nodes.document hdoc = jsoup.parse(source); string cleanhtml = hdoc.body().html(); documentbuilderfactory factory = documentbuilderfactory.newinstance(); factory.setvalidating(false); inputsource source = new inputsource(new stringreader(cleanhtml)); documentbuilder docb = factory.newdocumentbuilder(); document d = docb.parse(source); return d;
for xslt transformation don't need go full document first, inputsource
nicely.
along these lines...
/* stylesheet come getresourceasstream */ public string getfo(string rawhtml, inputstream stylestream) { org.jsoup.nodes.document hdoc = jsoup.parse(rawhtml); string cleanhtml = hdoc.body().html(); inputsource source = new inputsource(new stringreader(cleanhtml)); streamsource style = new streamsource(stylestream); transformerfactory tfactory = transformerfactory.newinstance(); transformer transformer = tfactory.newtransformer(style); streamresult xresult = new streamresult(new stringwriter()); transformer.setoutputproperty("omit-xml-declaration", "yes"); transformer.transform(source, xresult); string result = xresult.getwriter().tostring(); return result; }
of course need add error handling etc. let know how goes