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)); renderFO(foSource, req, res, inPdf); 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: Carlos Daniel Schafer [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, March 06, 2002 10:28 AM > To: [EMAIL PROTECTED] > Subject: RE: FOP embedding > > > I'm sorry > > Do you want to use FOP in a servlet to produce a PDF from > dynamically created XML and return the PDF to the > browser to display? > > Yes > > I have this files (FOP). > > I have code this servlet with created XML and I desidere dynamically > return the PDF. > > Do you want send this servlet for look? > > > > > -----Mensaje original----- > > De: Jim Urban [SMTP:[EMAIL PROTECTED]] > > Enviado el: miércoles, 06 de marzo de 2002 13:05 > > Para: [EMAIL PROTECTED] > > Asunto: RE: FOP embedding > > > > Can you please be more specific. Do you want to use FOP in a servlet to > produce a PDF from dynamically created XML and return the PDF to > the > browser to display? Are you having problems writing the Java code > to do > > this, or are you having problems with FOP not working? > > > > Jim > > > -----Original Message----- > > > From: Carlos Daniel Schafer [mailto:[EMAIL PROTECTED]] > > Sent: Wednesday, March 06, 2002 9:34 AM > > To: [EMAIL PROTECTED] > > Subject: FOP embedding > > > > > > Hi! > > > > I saw those examples the FOP > > I have problem with transformer XML to PDF from a servlet. How I to do? > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, email: [EMAIL PROTECTED] > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, email: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]