Here's how I do it:
        ByteArrayOutputStream pdfOutput = new ByteArrayOutputStream();

        try {
            Driver driver = new Driver(new InputSource (new
StringReader(transformed)),
                                          pdfOutput);
            driver.setRenderer(Driver.RENDER_PDF);
            driver.run();
        } catch (FOPException e) {
            if (m_logTrace) {
                Util.log(this, "FOP processing got exception " + e);
            }
            throw new RuntimeException(e.toString());
        }

"transformed" is a StringWriter that contains the XSL-FO output from the
XSLT transformation.  You could just as easily substitute the the servlet
output stream as the second parameter to the Driver instantiation, just be
sure to set the Content Type for the servlet response first.

Hope this helps.

-Jim
----- Original Message -----
From: "Sharan, Dharmendra" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, September 04, 2001 9:18 AM
Subject: Using FOP in Servlet - *dynamically* generating XSL:FO using XML
and XSLT


> Hi,
>
>     I am trying to have use XSL:FOP through servlet and I was hoping to
use
> XML and XSLT to dynamically generate the XSL:FOP format file to be passed
to
> Driver for rendering as PDF.
>
>    The example which comes with distribution uses xmlFile and xslFile,
> however I wanted to generate the XML and XSL at run time and to be able to
> pass the output into the Driver for rendering a PDF.
>
>     However I found that currently XSLTInputHandler constructor only
accepts
> xmlFile and xslFile?
>
>     Is there a possible way where I can have the xsl:fo be generated
> dynamically and be able to pass it to Driver as an InputSource for
> rendering. (since InputSource constructor does accept/allow InputStream)
>
>     Am I missing something ? or Do I need to write my own handler ?
>
>     I am lost here... pls. help.
>
>     Thanks (in anticipation!),
>
>     Dharmendra
>

Reply via email to