Re: How to show PDF file in jsp page II.
[EMAIL PROTECTED] wrote: I tried it , it works, but I have one great suspicion: Will it work even on remote server ? Why not? Just make sure you save it in a place browser has access to. -- Oleg Tkachenko eXperanto team Multiconn Technologies, Israel
Re: How to show PDF file in jsp page II.
Hi, your PDF file has to be accessible for tomcat, for example: Imagine your web application is stored under %TOMCAT_ROOT%/webapps/yourapp Then your PDF file has to be somewhere in your 'yourapp' directory. It is the same as html pages: you referene them (e.g. in html) with - relative path. So this link in http://localhost/bla.html will link to http://localhost/foo.html. Try this: put your PDF file under your webapp-root (called 'yourapp' above...) directory. And in your jsp: response.setRedirect(outPDF); // outPDF is "TMP.PDF" (without c:) // tomcat will look for 'yourapp/TMP.PDF' // If your JSP is e.g. accessible under http://localhost/myjsp.jsp // it will redirect to http://localhost/TMP.PDF which is also // remote accessible (if read access is permitted) I never tried response.setRedirect(), but I think this will work ;-) Marko At 17:05 06.11.2002 +0100, you wrote: I tried it , it works, but I have one great suspicion: Will it work even on remote server ? response.sendRedirect(outPDF); // outPDF is "C:/Program Files/Apache Tomcat 4.0/Fop/TMP.PDF" I have Tomcat and browser on one PC . Doesn't the browser thus open the PDF file directly, bypassing Tomcat ? If so, I think I should use URL as parameter. But how can I find out http address from inside the servlet? Thanks for any comments. > [EMAIL PROTECTED] wrote: > > > Yesterday, after a few good advices there from fop users I successfuly used > > this code to show pdf content in browser. It works in my JDeveloper 9i. > > > > File inputFile = new File(pdfFile); > > FileReader fr = new FileReader(inputFile); > > > > ByteArrayOutputStream baos = new ByteArrayOutputStream(); > > int ch; > > while((ch = fr.read()) != -1) { > > baos.write(ch); > > } > > > > byte[] content = baos.toByteArray(); > > response.setContentType("application/pdf"); > > response.setContentLength(content.length); > > response.getOutputStream().write(content); > > response.getOutputStream().flush(); > > Looks too convolute to me. If you have already created pdf file on a disk, why > do you process it by hands instead of rely on a web server? Just redirect > browser to the file, that will emulate reading static pdf, which works okay > even in IE (well, at least if extension is pdf). > I mean > response.sendRedirect("/foo/bar.pdf"); > > -- > Oleg Tkachenko > eXperanto team > Multiconn Technologies, Israel
Re: How to show PDF file in jsp page II.
I tried it , it works, but I have one great suspicion: Will it work even on remote server ? response.sendRedirect(outPDF); // outPDF is "C:/Program Files/Apache Tomcat 4.0/Fop/TMP.PDF" I have Tomcat and browser on one PC . Doesn't the browser thus open the PDF file directly, bypassing Tomcat ? If so, I think I should use URL as parameter. But how can I find out http address from inside the servlet? Thanks for any comments. > [EMAIL PROTECTED] wrote: > > > Yesterday, after a few good advices there from fop users I successfuly used > > this code to show pdf content in browser. It works in my JDeveloper 9i. > > > > File inputFile = new File(pdfFile); > > FileReader fr = new FileReader(inputFile); > > > > ByteArrayOutputStream baos = new ByteArrayOutputStream(); > > int ch; > > while((ch = fr.read()) != -1) { > > baos.write(ch); > > } > > > > byte[] content = baos.toByteArray(); > > response.setContentType("application/pdf"); > > response.setContentLength(content.length); > > response.getOutputStream().write(content); > > response.getOutputStream().flush(); > > Looks too convolute to me. If you have already created pdf file on a disk, why > do you process it by hands instead of rely on a web server? Just redirect > browser to the file, that will emulate reading static pdf, which works okay > even in IE (well, at least if extension is pdf). > I mean > response.sendRedirect("/foo/bar.pdf"); > > -- > Oleg Tkachenko > eXperanto team > Multiconn Technologies, Israel
Re: How to show PDF file in jsp page II.
[EMAIL PROTECTED] wrote: Yesterday, after a few good advices there from fop users I successfuly used this code to show pdf content in browser. It works in my JDeveloper 9i. File inputFile = new File(pdfFile); FileReader fr = new FileReader(inputFile); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int ch; while((ch = fr.read()) != -1) { baos.write(ch); } byte[] content = baos.toByteArray(); response.setContentType("application/pdf"); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); Looks too convolute to me. If you have already created pdf file on a disk, why do you process it by hands instead of rely on a web server? Just redirect browser to the file, that will emulate reading static pdf, which works okay even in IE (well, at least if extension is pdf). I mean response.sendRedirect("/foo/bar.pdf"); -- Oleg Tkachenko eXperanto team Multiconn Technologies, Israel
RE: How to show PDF file in jsp page ?
-Original Message- From: Gilson Nascimento Del Rei [mailto:[EMAIL PROTECTED] Sent: Monday, November 04, 2002 6:21 AM To: '[EMAIL PROTECTED]' Subject: RES: How to show PDF file in jsp page ? I newbie question... Why we have that read the pdf file ? Doesn't is a simple link sufficient for execute it ? I mean isn't it a browser work ? Gilson > - Mensagem original - > De: [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED] > Enviada em: segunda-feira, 4 de novembro de 2002 10:10 > Para: [EMAIL PROTECTED] > Assunto: Re: How to show PDF file in jsp page ? > > > Thanks to all, this code works ... > > > File inputFile = new File(pdfFile); > FileReader fr = new FileReader(inputFile); > > ByteArrayOutputStream baos = new ByteArrayOutputStream(); > int ch; > while((ch = fr.read()) != -1) { > baos.write(ch); > } > > byte[] content = baos.toByteArray(); > response.setContentType("application/pdf"); > response.setContentLength(content.length); > response.getOutputStream().write(content); > response.getOutputStream().flush(); > > This electronic transmission is strictly confidential to Smith & Nephew and intended solely for the addressee. It may contain information which is covered by legal, professional or other privilege. If you are not the intended addressee, or someone authorized by the intended addressee to receive transmissions on behalf of the addressee, you must not retain, disclose in any form, copy or take any action in reliance on this transmission. If you have received this transmission in error, please notify the sender as soon as possible and destroy this message.
Re: How to show PDF file in jsp page ?
Thanks to all, this code works ... File inputFile = new File(pdfFile); FileReader fr = new FileReader(inputFile); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int ch; while((ch = fr.read()) != -1) { baos.write(ch); } byte[] content = baos.toByteArray(); response.setContentType("application/pdf"); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush();
Re: How to show PDF file in jsp page ?
[EMAIL PROTECTED] wrote: I successfully created PDF , but now I don't know how to make browser show it like PDF (Acrobat is installed, when I open file directly in browser, all is ok). Take a look at docs/examples/embedding/FopServlet.java as an example how to return pdf. What must I do, to make browser use Acrobat plugin ? Thanks. The only way is to define application/pdf content type (+ some fiddling with .pdf at the end for a too smart browsers, search in archive, that's vfaq.) -- Oleg Tkachenko eXperanto team Multiconn Technologies, Israel
RE: How to show PDF file in jsp page ?
Is the browser IE? Try this: Add the parameter to GET query, so the URL will end with .pdf like this: http://./getPdf.jsp?id=&dummy=.pdf Michal -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Monday, November 04, 2002 11:51 AM To: [EMAIL PROTECTED] Subject: How to show PDF file in jsp page ? I successfully created PDF , but now I don't know how to make browser show it like PDF (Acrobat is installed, when I open file directly in browser, all is ok). If I use this code: File inputFile = new File(pdfFile); FileReader fr = new FileReader(inputFile); int c; while( (c = in.read()) != -1) out.write(c); fr.close() , it shows only %PDF-1.3 %^?? 4 0 obj << /Type /Info /Producer (null) >> endobj 5 0 obj << /Length 518 /Filter [ /ASCII85Decode /FlateDecode ] >> stream GasIe]5GM?%,Cdrr.2-t77e1)A-gNlh$SBW3]IXolHoP1:b%cI[r>4J(X"OY7ipn7qX1?O^,[EMAIL PROTECTED] lku6;kXe'1hU0KY_)ImgG*1CNnEe%YAdYqXKst:k4#- ... When I placed on JSP page this line response.setContentType("application/pdf"); , the result is similar: %PDF-1.3 %^?? 4 0 obj << /Type /Info /Producer (FOP 0.20.3) >> endobj 5 0 obj << /Length 518 /Filter [ /ASCII85Decode /FlateDecode ] >> stream ... What must I do, to make browser use Acrobat plugin ? Thanks.