I posted this about a week ago, but here you go again...

Jim

public void doPost(HttpServletRequest req, HttpServletResponse res)
                 throws ServletException
{
        ... your code
        try
        {
                String xmlString = new String("...."); // your xml
                TransformerFactory tFactory = TransformerFactory.newInstance();
                File   foFile        = new File("foXslFile.xsl");
                Source foXslSource   = new StreamSource(foFile);
                Transformer pdfTransformer = tFactory.newTransformer(foXslSource);
                Writer out = new StringWriter();
                Source xmlSource = new StreamSource(new StringReader(xmlString));
                pdfTransformer.transform(xmlSource, new StreamResult(out));
                out.close();
                String fopstring = out.toString();
                InputSource foSource = new InputSource(new StringReader(fopstring));
                ByteArrayOutputStream baout = new ByteArrayOutputStream();
                Driver driver = new Driver(foSource , baout);
                res.setContentType("application/pdf");
                driver.setRenderer(Driver.RENDER_PDF);
                driver.run();
                byte[] content = baout.toByteArray();
                res.setContentLength(content.length);   // This keeps IE happy!!!!
                res.getOutputStream().write(content);
                res.getOutputStream().flush();
                res.flushBuffer();
        }
        catch (Exception e)
        {
                System.err.println("Exception in init:  " + e.toString());
                e.printStackTrace();
        }
        ... more code
}


> -----Original Message-----
> From: David B. Bitton [mailto:[EMAIL PROTECTED]]
> Sent: Friday, March 08, 2002 11:27 PM
> To: fop-dev
> Subject: HowTo Render PDF from XML string and XSL file
>
>
> I have spent some time looking at the embedding sample, and I have some
> questions.  I have successfully implemented FOP as a WebService having the
> XSL-FO data posted to the service and the service rendering the file onto
> the local machine.  Now I want to do the XML/XSL to XSL-FO
> transform in the
> WebService.
>
> I noticed that the transform occurs in the XSLInputHandler.  This then
> allows for an InputSource and XMLReader to be available to the
> Driver.render() overloaded method.  The unfortunate part is the
> XSLInputHandler constructor only takes File object, no stream.
> I'd like to
> avoid bouncing the XML data off the disk just to statisfy this requirement
> for using XSLInputHandler.
>
> So, my question is this, how can I arrive at the same results, an
> InputSource and an XMLReader interfaced object for Driver.render()?  Or
> better yet, what I'm asking is what is going on inside
> XSLInputHandler that
> I can slurp out into my code.  Tx :)
>
> --
>
> David B. Bitton
> [EMAIL PROTECTED]
> www.codenoevil.com
>
> Diversa ab illis virtute valemus.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to