#1
  1. php-oriented object
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    0x9832053
    Posts
    173
    Rep Power
    14

    PDF Generation with Apache FOP


    Hi all!

    i'm stuck with an error that comes out when i try to generate a PDF with FOP (XML+XSLT transformation).
    the exception is:
    com.inqmy.lib.xsl.xslt.XSLOutputException: Error writing output. -> org.apache.fop.apps.FOPException: Root element must be root, not (unknown)

    but what does this mean??? the application is running on a Win2k machine with the SAP J2EE Engine.

    when i run it on my JBoss test server it's all fine! and yes...there are the same libraries and files...so what??

    here is the method that generates the pdf:
    Code:
        public void renderXML(String xmlFileName, HttpServletResponse response) throws ServletException {
            try {
                System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
                System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");
                System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.processor.TransformerFactoryImpl");
                System.setProperty("org.xml.sax.driver", "org.apache.xerces.parsers.SAXParser");
    
                ByteArrayOutputStream out = new ByteArrayOutputStream();
    
                Driver driver = new Driver();
                driver.setRenderer(Driver.RENDER_PDF);
                driver.setOutputStream(out);
    
                Source xsltSrc = new StreamSource(new File(xslLocation));
                Transformer transformer = this.transformerFactory.newTransformer(xsltSrc);
    
                Result res = new SAXResult(driver.getContentHandler());
    
                Source src = new StreamSource(new File(xmlFileName));
    
                transformer.transform(src, res);
    
                response.setContentType(CONTENT_TYPE_PDF);
                response.addHeader("Content-Disposition", "attachment;filename=listino.pdf;");
    
                response.setContentLength(out.size());
                response.getOutputStream().write(out.toByteArray());
                response.getOutputStream().flush();
    
            } catch (Exception ex) {
                throw new ServletException(ex);
            }
        }
    Tnx!
    Last edited by tank80; July 24th, 2003 at 05:41 AM.

IMN logo majestic logo threadwatch logo seochat tools logo