Hi all.
I transform a xml file and add FO vocabulary, generating a PDF with fop afterwards. Now that I got it work using xalan and fop from the command line I embedded both into a JSP and a bean following the example code from docs/examples/embedding.
The problem: When I generate the PDF with the JSP my fo:basic-links don't make it into the PDF. If I dump the FO DOM tree to a file and use fop from the commandline the links are present in the PDF.
Here is the code I use:
<!-- JSP Code --> <% byte[] result = null; pdfHelper.FOPit( docAllInOne, "allInOne2FO.xsl" ); response.setContentType("application/pdf"); response.setContentLength(result.length); response.getOutputStream().write(result); response.getOutputStream().flush(); %>
/* Bean */ public byte[] FOPit( Document doc, String styleSheet ) {
XMLTransform tf = new XMLTransform(); if ( !tf.setStyleSheet( styleSheet ) ) return null;
/* Transform the Document. */ DOMResult result = tf.process( doc ); if ( result == null ) return null; /* * allInOne_1.fo used with fop on the command line * creates links in the PDF file. */ XMLWriter.debugToFile( (Document)result.getNode(), "allInOne_1.fo" );
DocumentInputSource source = new DocumentInputSource(); source.setDocument( (Document)result.getNode() );
ByteArrayOutputStream out = new ByteArrayOutputStream();
Hierarchy hierarchy = Hierarchy.getDefaultHierarchy(); Logger log = hierarchy.getLoggerFor("fop"); log.setPriority(Priority.DEBUG); Driver driver = new Driver( source, out ); driver.setLogger( log ); driver.setRenderer(Driver.RENDER_PDF); try { driver.run(); } catch ( Exception e ) { e.printStackTrace(); }
return out.toByteArray();
} // end FOPit()
I'd be glad if someone could give me a hint where the reason for this behavior might be found.
Ralf