Re: Anything wrong with this code (please look at attachements)
Thanks it worked for me too now both in Netscape and IE. However what if I wanted to embed to PDF results from FOP inside some HTML code for formatting purposes?, is that possible at all. What I mean is is possible to send the PDF and the HTML back to the client in some fashion? Greetings, Carmelo - Original Message - From: Matt Savino [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, September 26, 2001 7:20 PM Subject: Re: Anything wrong with this code (please look at attachements) For one thing it looks like you are mixing PDF and HTML content in your response: ServletOutputStream out = response.getOutputStream(); try { out.println(HTML\n); out.println(HEAD\n); out.println(BODY\n); out.println(CENTERH1FOP and PDF Creation./H1/CENTER\n); renderFO(response); out.println(/BODY\n); out.println(/HTML\n); } and byte[] content = outPDF.toByteArray(); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().println(BRBR); response.getOutputStream().println(There should be a PDF image above); response.flushBuffer(); response.getOutputStream().flush(); For some reason, Netscape doesn't mind this. But IE seems to create an Http error that's related to the discrepancy in the content length of the response. (At least with Weblogic). I removed all your out.println(..) calls and the code works. Also I have noticed a weird bug where IE sometimes doesn't recognize PDF, even though you set the response type to application/pdf. I was using the FopServlet example from .20.1. It worked fine if used Netscape. The weird thing is if I clicked back, then forward in IE, it recognized the PDF and loaded the plugin. I think I solved the problem by mapping the servlet URI to FopServletTest.pdf and sending the FO filename as a POST form instead of a GET. Hope this helps, Matt Carmelo Montanez wrote: Hello all Thanks Sempri for all your comments. For anyone interested, I am attaching a very slimed down copy of my Servlet. I am hardwiring the file name (FO file) inside the servlet (for convenience of running). I am also attaching a dummy HTML file to call the servlet (no parameters are retrieved from the HTML by the servlet). I am also attaching the FO file I am running this using Tomcat. If anyone please try an attempt to run the servlet. I am still getting stuff (as you will see) on the browser. Please look at the import statements (most of them are comments) to see which classes you need, I can can provide them if need be. I am using FOP's latest version. Greetings, Carmelo Name: testPDF.java testPDF.javaType: unspecified type (application/octet-stream) Encoding: quoted-printable Name: test.html test.htmlType: Hypertext Markup Language (text/html) Encoding: 7bit Name: cbpbp-background-color4.fo cbpbp-background-color4.foType: unspecified type (application/octet-stream) Encoding: quoted-printable --- - 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]
Re: Anything wrong with this code
Hi, 01c701c145fd$006f6f70$[EMAIL PROTECTED]"> When the PDF data is sent back to my client. Am I suppose to tell my client (IE6) that this is a PDF file (or a stream). I do set response.contentType to "application/pdf". This is an information that you send correctly to the client setting contentType() with this code: response.setContentType("application/pdf"); 01c701c145fd$006f6f70$[EMAIL PROTECTED]"> Am I suppose to do something else? what do you want to do? D.Semprini 01c701c145fd$006f6f70$[EMAIL PROTECTED]"> Carmelo - Original Message - From: Semprini Davide To: [EMAIL PROTECTED] Sent: Tuesday, September 25, 2001 3:51AM Subject: Re: Anything wrong with thiscode Hi, PDF file is a binary file!!! Use this code it'swork: byte[] content = outPDF.toByteArray(); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); D.Semprini CarmeloMontanez wrote: 02be01c1452d$7953e270$[EMAIL PROTECTED]" type="cite"> Hi All: I know that my browser can display PDF propertly now, however the following piece of code (that generates PDF data) sends the data back to the client (IE6) and still does not not looks like PDF at all. Can someone please tell me if there is something wrong with this code. By the way (out = response.getOutputStream() and "foFile" comes from an "FO" file). public void renderFO(InputSource foFile, HttpServletResponse response) throws IOException { try { ByteArrayOutputStream outPDF = new ByteArrayOutputStream(); response.setContentType("application/pdf"); Driver driver = new Driver(foFile, outPDF); driver.setRenderer(Driver.RENDER_PDF); driver.setOutputStream(outPDF); driver.run(); byte[] content = outPDF.toByteArray(); response.setContentLength(content.length); out.write(content); out.flush(); } catch (Exception ex) { System.out.println(ex); } Thanks, Carmelo Montanez Carmelo Montanez NIST Stop 8970 Gaithersburg, MD 20899 [EMAIL PROTECTED]
Anything wrong with this code (please look at attachements)
Hello all Thanks Sempri for all your comments. For anyone interested, I am attaching a very slimed down copy of my Servlet. I am hardwiring the file name (FO file) inside the servlet (for convenience of running). I am also attaching a "dummy" HTML file to call the servlet (no parameters are retrieved from the HTML by the servlet). I am also attaching the FO file I am running this using Tomcat. If anyone please try an attempt to run the servlet. I am still getting "stuff" (as you will see) on thebrowser. Please look at the "import" statements (most of them are comments) to see which classes you need, I can can provide them if need be. I am using FOP's latest version. Greetings, Carmelo testPDF.java This is an FOP PDF generation test This is just a test cbpbp-background-color4.fo - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
Re: Anything wrong with this code
Hi, PDF file is a binary file!!! Use this code it's work: byte[] content = outPDF.toByteArray(); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); D.Semprini Carmelo Montanez wrote: 02be01c1452d$7953e270$[EMAIL PROTECTED]"> Hi All: I know that my browser can display PDF propertly now, however the following piece of code (that generates PDF data) sends the data back to the client (IE6) and still does not not looks like PDF at all. Can someone please tell me if there is something wrong with this code. By the way (out = response.getOutputStream() and "foFile" comes from an "FO" file). public void renderFO(InputSource foFile, HttpServletResponse response) throws IOException { try { ByteArrayOutputStream outPDF = new ByteArrayOutputStream(); response.setContentType("application/pdf"); Driver driver = new Driver(foFile, outPDF); driver.setRenderer(Driver.RENDER_PDF); driver.setOutputStream(outPDF); driver.run(); byte[] content = outPDF.toByteArray(); response.setContentLength(content.length); out.write(content); out.flush(); } catch (Exception ex) { System.out.println(ex); } Thanks, Carmelo Montanez Carmelo Montanez NIST Stop 8970 Gaithersburg, MD 20899 [EMAIL PROTECTED]
Re: Anything wrong with this code
When the PDF data is sent back to my client. Am I suppose to tell my client (IE6) that this is a PDF file (or a stream). I do set response.contentType to "application/pdf". Am I suppose to do something else? Carmelo - Original Message - From: Semprini Davide To: [EMAIL PROTECTED] Sent: Tuesday, September 25, 2001 3:51 AM Subject: Re: Anything wrong with this code Hi,PDF file is a binary file!!!Use this code it's work:byte[] content = outPDF.toByteArray(); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); D.SempriniCarmelo Montanez wrote: 02be01c1452d$7953e270$[EMAIL PROTECTED] type="cite"> Hi All: I know that my browser can display PDF propertly now, however the following piece of code (that generates PDF data) sends the data back to the client (IE6) and still does not not looks like PDF at all. Can someone please tell me if there is something wrong with this code. By the way (out = response.getOutputStream() and "foFile" comes from an "FO" file). public void renderFO(InputSource foFile, HttpServletResponse response) throws IOException { try { ByteArrayOutputStream outPDF = new ByteArrayOutputStream(); response.setContentType("application/pdf"); Driver driver = new Driver(foFile, outPDF); driver.setRenderer(Driver.RENDER_PDF); driver.setOutputStream(outPDF); driver.run(); byte[] content = outPDF.toByteArray(); response.setContentLength(content.length); out.write(content); out.flush(); } catch (Exception ex) { System.out.println(ex); } Thanks, Carmelo Montanez Carmelo MontanezNIST Stop 8970Gaithersburg, MD 20899 [EMAIL PROTECTED]
Anything wrong with this code
Hi All: I know that my browser can display PDF propertly now, however the following piece of code (that generates PDF data) sends the data back to the client (IE6) and still does not not looks like PDF at all. Can someone please tell me if there is something wrong with this code. By the way (out = response.getOutputStream() and "foFile" comes from an "FO" file). public void renderFO(InputSource foFile, HttpServletResponse response) throws IOException { try { ByteArrayOutputStream outPDF = new ByteArrayOutputStream(); response.setContentType("application/pdf"); Driver driver = new Driver(foFile, outPDF); driver.setRenderer(Driver.RENDER_PDF); driver.setOutputStream(outPDF); driver.run(); byte[] content = outPDF.toByteArray(); response.setContentLength(content.length); out.write(content); out.flush(); } catch (Exception ex) { System.out.println(ex); } Thanks, Carmelo Montanez Carmelo MontanezNIST Stop 8970Gaithersburg, MD 20899 [EMAIL PROTECTED]