how starting FOP without XML-File
Hallo I generate my PDF-File in a servlet: File xmlFile = new File("c:/temp/test.xml"); File xslFile = new File("c:/temp/test.xsl"); InputHandler inputHandler = new XSLTInputHandler(xmlFile, xslFile); org.xml.sax.XMLReader parser = inputHandler.getParser(); driver.buildFOTree(parser, inputHandler.getInputSource()); driver.format(); driver.setOutputStream(out); driver.render(); In the above example the xml input source is a file. But I would rather passthe input source xml file (text.xml) in the memory. It's possible and howcan I do this? Thanks Marc BEGIN:VCARD VERSION:2.1 N:Jenzer;Marc;;Herr FN:Marc Jenzer ORG:j-solution GmbH TITLE:Geschäftsführer / Consultant TEL;WORK;VOICE:+41 1 851 36 03 TEL;CELL;VOICE:+41 79 543 49 02 TEL;WORK;FAX:+41 1 851 36 04 ADR;WORK:;;Geerenstrasse 18;Niederglatt;;CH-8172 LABEL;WORK;ENCODING=QUOTED-PRINTABLE:Geerenstrasse 18=0D=0ANiederglatt CH-8172 URL:http://www.j-solution.ch URL:http://www.j-solution.ch KEY;X509;ENCODING=BASE64: MIIFDDCCA/SgAwIBAgIGAQIAABLAMA0GCSqGSIb3DQEBBQUAMIGZMQswCQYDVQQGEwJDSDEU MBIGA1UEChMLU3dpc3NrZXkgQUcxHjAcBgNVBAsTFTAwODUxMDAwMDAwMDUwMDAwMDM5NDEb MBkGA1UECxMSUHVibGljIENBIFNlcnZpY2VzMRAwDgYDVQQHEwdadWVyaWNoMSUwIwYDVQQD ExxTd2lzc2tleSBQZXJzb25hbCBJRCBDQSAxMDI0MB4XDTAxMDIwODE0MDA0M1oXDTAzMDIw ODIzNTkwMFowgZ8xGzAZBgNVBAoTElByaXZhdGUgSW5kaXZpZHVhbDEeMBwGA1UECxMVMDA4 NTEwMDAxMzEyMDAwMDAwMTUwMRMwEQYDVQQLEwoyNC4wMy4xOTc0MQswCQYDVQQGEwJDSDEU MBIGA1UEAxMLTWFyYyBKZW56ZXIxKDAmBgkqhkiG9w0BCQEWGW1hcmMuamVuemVyQGotc29s dXRpb24uY2gwgZ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L+SXgP1Lo KgBifz2+RlYUMYnFyDF1rYsPOrlxGT2wsusb03LjNMvpYM8F+C2tF5bzfTy0V2+obw9Tymvp A01pYTPU+OXGFhfL/x9miRkF32daOocaNAQTebErBFkHkVjsh/OXjtk1Zn35jJIYh6Q/z0aE EMAIL;PREF;INTERNET:[EMAIL PROTECTED] REV:20010209T164031Z END:VCARD - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
RE: how starting FOP without XML-File
Thanks for the answer! But with your solution, I can't pass the fop xsl file. This file is on the filesystem. Could you help me? Thanks -Original Message-This code will read the XML from a String object and write the PDF outputback to the browser.: try { String fopstring = your function to generate the XML InputSource foSource = InputSource(new StringReader(fopstring)); ByteArrayOutputStream out = new ByteArrayOutputStream(); response.setContentType("application/pdf"); Driver driver = new Driver(foSource, out); driver.setRenderer(Driver.RENDER_PDF); driver.run(); byte[] content = out.toByteArray(); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); response.flushBuffer(); }Jim Urban -Original Message- From: Marc Jenzer [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 11, 2001 7:14 AM To: [EMAIL PROTECTED] Subject: how starting FOP without XML-File Hallo I generate my PDF-File in a servlet: File xmlFile = new File("c:/temp/test.xml"); File xslFile = new File("c:/temp/test.xsl"); InputHandler inputHandler = new XSLTInputHandler(xmlFile,xslFile); org.xml.sax.XMLReader parser = inputHandler.getParser(); driver.buildFOTree(parser, inputHandler.getInputSource()); driver.format(); driver.setOutputStream(out); driver.render(); In the above example the xml input source is a file. But I would ratherpass the input source xml file (text.xml) in the memory. It's possible andhow can I do this? Thanks Marc
RE: how starting FOP without XML-File
If I understand you correctly, in your servlet you wish to apply an xsl style sheet (from a file) to an xml string in memory to generate a FO xml string in memory to run through FOP to generate a PDF in memory which you want to return to the browser. If that is the case, here are the pieces for your servlet... These are class variables... TransformerFactory tFactory= null; Transformertransformer = null; Place this code in your init method to save reading and parsing the xsl file each time your servlet is called... tFactory = TransformerFactory.newInstance(); String xslFile = myfile.xsl; File theFile = new File(xslFile); Source xslSource = new StreamSource(theFile); transformer = tFactory.newTransformer(xslSource); This code goes in your doGet / doPost method and replaces the code from the previous email... try { String xmlString = ... function to generate your xml String. Writer out = new StringWriter(); Source xmlSource = new StreamSource(new StringReader(xmlString)); transformer.transform(xmlSource, new StreamResult(out)); out.close(); String fopstring = out.toString(); InputSource foSource = InputSource(new StringReader(fopstring)); ByteArrayOutputStream out = new ByteArrayOutputStream(); response.setContentType(application/pdf); Driver driver = new Driver(foSource, out); driver.setRenderer(Driver.RENDER_PDF); driver.run(); byte[] content = out.toByteArray(); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); } I hope this helps. I wish this example was part of the examples provided with FOP. Maybe a FOP developer (I'm just a user) can add an example like this to the FOP package. Jim Urban -Original Message- From: Marc Jenzer [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 11, 2001 8:27 AM To: [EMAIL PROTECTED] Subject: RE: how starting FOP without XML-File Thanks for the answer! But with your solution, I can't pass the fop xsl file. This file is on the filesystem. Could you help me? Thanks -Original Message- This code will read the XML from a String object and write the PDF output back to the browser.: try { String fopstring = your function to generate the XML InputSource foSource = InputSource(new StringReader(fopstring)); ByteArrayOutputStream out = new ByteArrayOutputStream(); response.setContentType(application/pdf); Driver driver = new Driver(foSource, out); driver.setRenderer(Driver.RENDER_PDF); driver.run(); byte[] content = out.toByteArray(); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); response.flushBuffer(); } Jim Urban -Original Message- From: Marc Jenzer [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 11, 2001 7:14 AM To: [EMAIL PROTECTED] Subject: how starting FOP without XML-File Hallo I generate my PDF-File in a servlet: File xmlFile= new File(c:/temp/test.xml); File xslFile= new File(c:/temp/test.xsl); InputHandler inputHandler = new XSLTInputHandler(xmlFile, xslFile); org.xml.sax.XMLReader parser = inputHandler.getParser(); driver.buildFOTree(parser, inputHandler.getInputSource()); driver.format(); driver.setOutputStream(out); driver.render(); In the above example the xml input source is a file. But I would rather pass the input source xml file (text.xml) in the memory. It's possible and how can I do this? Thanks Marc - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
RE: how starting FOP without XML-File
Jim, Thanks a lot for your help! It works now! Cheers Marc