Hello list.
I'm trying to move from 0.20.5 to 0.91beta.
Here's a problem I'm facing: following the instruction
in the documentation that comes the 0.91beta, lead to
code that doesn't compile.
So I modified it as follows to be able to compile, but
the result I get executing it wrong.. I get an empty
text/html document instead of the expected application/pdf
below's the code in the get/post servlet method and probably
the main difference from the documentation is the parameter
in the Fop constructor MimeConstants.MIME_PDF vs Constants.RENDER_PDF).
Note that this code is the same I used with FOP 0.20.5 with
just a few modification:
1) no Driver, but Fop
2) no driver.run() but transformer.transform()
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
try {
OfferBean offer = (OfferBean)request.getAttribute("offer");
ArrayList offerPerformances =
(ArrayList)request.getAttribute("offerPerformances");
String s = PdfCreator.getFO(offer, offerPerformances);
StringReader sr = new StringReader(s);
// Driver driver = new Driver();
// driver.setRenderer(Driver.RENDER_PDF);
Fop fop = new Fop(MimeConstants.MIME_PDF);
//Setup a buffer to obtain the content length
ByteArrayOutputStream out = new ByteArrayOutputStream();
fop.setOutputStream(out);
//Setup input
Source src = new StreamSource(sr);
// driver.setInputSource(src);
// driver.run();
Result res = new SAXResult(fop.getDefaultHandler());
// ottengo il transformer
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.transform(src, res);
//Prepare response
response.setContentType("application/pdf");
response.setContentLength(out.size());
//Send content to Browser
response.getOutputStream().write(out.toByteArray());
response.getOutputStream().flush();
}
catch (Exception e) {
e.printStackTrace();
}
}
Any advice/hints?
Thank you and best regards.
--
Robi
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]