FOPException If an error occurs during the rendering of the
* XSL-FO
* @throws TransformerException If an error occurs while parsing the
input
* file
*/
protected byte[] renderFO(String fo)
throws FOPException, TransformerException {
//Setup source
Source foSrc = convertString2Source(fo);
//Setup the identity transformation
Transformer transformer = this.transFactory.newTransformer();
//Start transformation and rendering process
return render(foSrc, transformer);
}
/**
* Renders an XML file into a PDF file by applying a stylesheet
* that converts the XML to XSL-FO. The PDF is written to a byte array
* that is returned as the method's result.
* @param xml the XML file
* @param xslt the XSLT file
* @return byte[] the rendered PDF file
* @throws FOPException If an error occurs during the rendering of the
* XSL-FO
* @throws TransformerException If an error occurs during XSL
* transformation
*/
protected byte[] renderXML(String xml, String xslt)
throws FOPException, TransformerException {
//Setup sources
Source xmlSrc = convertString2Source(xml);
Source xsltSrc = convertString2Source(xslt);
//Setup the XSL transformation
Transformer transformer = this.transFactory.newTransformer(xsltSrc);
//Start transformation and rendering process
return render(xmlSrc, transformer);
}
/**
* Renders an input file (XML or XSL-FO) into a PDF file. It uses the
JAXP
* transformer given to optionally transform the input document to
XSL-FO.
* The transformer may be an identity transformer in which case the
input
* must already be XSL-FO. The PDF is written to a byte array that is
* returned as the method's result.
* @param src Input XML or XSL-FO
* @param transformer Transformer to use for optional transformation
* @return byte[] the rendered PDF file
* @throws FOPException If an error occurs during the rendering of the
* XSL-FO
* @throws TransformerException If an error occurs during XSL
* transformation
*/
protected byte[] render(Source src, Transformer transformer)
throws FOPException, TransformerException {
//Setup FOP
Driver driver = new Driver();
driver.setRenderer(Driver.RENDER_PDF);
// driver.initialize();
//Setup output
ByteArrayOutputStream out = new ByteArrayOutputStream();
driver.setOutputStream(out);
//Make sure the XSL transformation's result is piped through to FOP
Result res = new SAXResult(driver.getContentHandler());
//Start the transformation and rendering process
transformer.transform(src, res);
//Return the result
return out.toByteArray();
}
}
Thanks! JV.
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
stefan ziel
clan informática do brasil ltda.
mailto:[EMAIL PROTECTED]
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]