You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by "Rajagopal.V" <ra...@usa.net> on 2001/04/24 23:49:37 UTC

Strange problem generating PDF From XML-XSL

Hi all
Im running JServ 1.1 on Apache and am using FOP 0.18 . Im trying to writea
servlet which takes an XML and XSL file and generate a pdf from that. the
strange thing is that if i create the fo file separately using
XSLTransform(combining xml and xsl) and WRITE it to a physical file and then
give that file as an input to the Driver class, it is able to generate my pdf.

But if i dont create a physical file but just pass the output of XSLTransform
into the Driver, it gives me a
Unknown formatting object ^root
Ive seen many discussion on this forum saying that it mite be a classpath
problem if it happens but if its a classpath problem, then the former case
shud also not work. This is thet portion of code which doesnt work.
XSLTInputHandler xsltSource = new XSLTInputHandler(new File(xmlFile), new
File(xslFile));
ByteArrayOutputStream out= new ByteArrayOutputStream();
Driver driver = new Driver(xsltSource.getInputSource(), out);
driver.run();

and then get the contents of out and write it to the output.

But the former case of creating a separate file works!!!. Why is this.

TIA
Raj

____________________________________________________________________
Get free email and a permanent address at http://www.netaddress.com/?N=1

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org


Re: Strange problem generating PDF From XML-XSL

Posted by Bracchi Cabannes Christophe <ch...@ac-toulouse.fr>.
  Hi !

  Try to use :

    java.io.Writer writer = new java.io.StringWriter();
    org.apache.fop.tools.xslt.XSLTransform.transform(xmlFile, xsltFile, writer);
    writer.flush();
    writer.close();
    java.io.Reader reader;
    reader = new java.io.StringReader(writer.toString());
    org.xml.sax.InputSource foFile = new org.xml.sax.InputSource(reader);

for production of fo and :

    response.setContentType("application/pdf");
    java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
    org.apache.fop.apps.Driver driver = new org.apache.fop.apps.Driver(foFile,
out);
    driver.setRenderer(org.apache.fop.apps.Driver.RENDER_PDF);
    driver.run();
    byte[] content = out.toByteArray();
    response.setContentLength(content.length);
    response.getOutputStream().write(content);
    response.getOutputStream().flush();

for production of pdf for the client with :

    String xmlFile, String xsltFile, javax.servlet.http.HttpServletResponse
response

If you use Tomcat, BE CAREFUL, the fop.jar will be the FIRST class in the
classpath.

Christophe.

"Rajagopal.V" a �crit :

> Hi all
> Im running JServ 1.1 on Apache and am using FOP 0.18 . Im trying to writea
> servlet which takes an XML and XSL file and generate a pdf from that. the
> strange thing is that if i create the fo file separately using
> XSLTransform(combining xml and xsl) and WRITE it to a physical file and then
> give that file as an input to the Driver class, it is able to generate my pdf.
>
> But if i dont create a physical file but just pass the output of XSLTransform
> into the Driver, it gives me a
> Unknown formatting object ^root
> Ive seen many discussion on this forum saying that it mite be a classpath
> problem if it happens but if its a classpath problem, then the former case
> shud also not work. This is thet portion of code which doesnt work.
> XSLTInputHandler xsltSource = new XSLTInputHandler(new File(xmlFile), new
> File(xslFile));
> ByteArrayOutputStream out= new ByteArrayOutputStream();
> Driver driver = new Driver(xsltSource.getInputSource(), out);
> driver.run();
>
> and then get the contents of out and write it to the output.
>
> But the former case of creating a separate file works!!!. Why is this.
>
> TIA
> Raj
>
> ____________________________________________________________________
> Get free email and a permanent address at http://www.netaddress.com/?N=1
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
> For additional commands, email: fop-dev-help@xml.apache.org