I went back to the other mails. So now, it's clear what's wrong. As Jörg said, it's bad to write the output from FOP directly to the servlet's OutputStream. That's where you have to use a ByteArrayOutputStream. There's no easy way around it, I think. But the intermediate buffer between XSLT and FOP is still bad and unnecessary. So below you find a modified version of the code your posted on 2003-04-14. Warning: just a hack-up, untested, but should work IMO.
public class XURLPDF extends HttpServlet { public static final String XML_REQUEST_PARAM = "xml"; public static final String XSL_REQUEST_PARAM = "xsl"; Logger log = null; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { if(log == null) { log = new ConsoleLogger(ConsoleLogger.LEVEL_WARN); MessageHandler.setScreenLogger(log); } try { String xmlParam = request.getParameter(XML_REQUEST_PARAM); String xslParam = request.getParameter(XSL_REQUEST_PARAM); if((xmlParam != null) && (xslParam != null)) { response.setContentType("application/pdf"); Driver driver = new Driver(); Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); driver.setLogger(logger); MessageHandler.setScreenLogger(logger); driver.setRenderer(Driver.RENDER_PDF); //driver.setOutputStream(response.getOutputStream()); ByteArrayOutputStream baout = new ByteArrayOutputStream(16384); //The parameter 16384 initializes the initial buffer to //16KB to reduce memory reallocations by //ByteArrayOutputStream driver.setOutputStream(baout); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(new StreamSource(xslParam)); Source src=new StreamSource(xmlParam); Result res = new SAXResult(driver.getContentHandler()); transformer.transform(src, res); final byte[] content = out.toByteArray(); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); } else { PrintWriter out = response.getWriter(); out.println("<html><head><title>Error</title></head><body><h1>FopServlet Error</h1><h3>request param not given.</body></html>"); } } catch (Exception ex) { throw new ServletException(ex); } } } If you care about performance you should consider caching stylesheets or using XSLTC. On 17.04.2003 18:25:40 david.bg wrote: > Hi all, > > Adam: > If you use adobe acrobat 4.0, sometimes the pdf opens in the browser as > a blank page. I try upgrade acrobat to 5.0 and all works, but I found the > code posted in another mail, and it seems correct. (Jeremias says it's > inefficient). > > Jeremias: If you use the code from exampleXML2PDF in a servlet... well, > read the first line: IEx fails sometimes... :) I think there will be another > way to do it, but I don't know how: XPDF code works, and lag isn't > important... Jeremias Maerki --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]