  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | JSP - A mailing list about Java Server Pages specification and reference | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | PDF From JSP page - Some Urgent help needed | PDF From JSP page - Some Urgent help needed 2006-07-20 - By Satish
Back Hello,
Thanks for the sample code, I got it, now I have started running into problems.
I used the HelloWorld.jsp page in my application server to test. generating a PDF from jsp page. Though u mentioned the problems associated with use of JSP page. I have to use it because of limitations of the application and technology we are using. I cannot use servlets -not possible.
I am copying my code below, I tried to compile my JSP page and I see that the client browser my browser is IE.6.0 and FireFox 1.0.7 (both are failing) to generate a PDF. In IE I see that the client is calling Acrobat Reader but I get a blank screen and the following message
* File name does not begin with %PDF-*
But in FireFox its just a blank screen.
Sometimes when I tried to modify small pieces of code to test. I also got java.io exception and said *document does not have pages*. I used the same logic as tutorial hello world code.
My JSP is located in Oracle Apps and its powered by Oracle Apache server. I would appreciate if you can give me an approach or point me to an example, to resolve this issue. I have to generate a PDF of some data available to me in the session. I am even ok with the approach of creating a temp.pdf on the server for every user , I can open a file to display it to the user, delete it when he closes the pdf, if so how do i do? any examples available? i tried searching the archives could not come across the one i need. Thanks for your help in advance. I need to get through the first step, and I am sure everything else will be easy after, I wanna generate a pdf from Helloworld.jsp.
Here is my code -- helloworld.jsp- same as what is available in the itext tutorial
<%@ page import="java.io.*"%> <%@ page import="com.lowagie.text.*"%> <%@ page import="com.lowagie.text.pdf.*"%>
<% try{ response.setContentType("application/pdf"); Document doc = new Document(); java.io.ByteArrayOutputStream .html>java.io.ByteArrayOutputStream java.io.ByteArrayOutputStream .java.html> ' border=0> buffer = new java.io.ByteArrayOutputStream .html>java.io.ByteArrayOutputStream java.io.ByteArrayOutputStream .java.html> ' border=0>(); PdfWriter.getInstance(doc, buffer); doc.open(); doc.add(new Paragraph("Hello World")); java.io.DataOutput ot = new java.io.DataOutput Stream( response.getOutputStream()); byte[] bytes = buffer.toByteArray(); response.setContentLength(bytes.length + 100); for( int i = 0; i < bytes.length; i++ ) {ot.writeByte( bytes[i] ); } doc.close();
}
catch(Exception e){ e.printStackTrace(); }
%>
<div><br>Hello,</div> <div> </div> <div>Thanks for the sample code, I got it, now I have started running into problems.</div> <div> </div> <div>I used the HelloWorld.jsp page in my application server to test. generating a PDF from jsp page. Though u mentioned the problems associated with use of JSP page. I have to use it because of limitations of the application and technology we are using. I cannot use servlets -not possible. </div> <div> </div> <div>I am copying my code below, I tried to compile my JSP page and I see that the client browser my browser is IE.6.0 and FireFox 1.0.7 (both are failing) to generate a PDF. In IE I see that the client is calling Acrobat Reader but I get a blank screen and the following message </div> <div> </div> <div><strong> File name does not begin with %PDF-</strong></div> <div><br>But in FireFox its just a blank screen.</div> <div> </div> <div>Sometimes when I tried to modify small pieces of code to test. I also got <a href="http://java.io">java.io</a> exception and said <strong>document does not have pages</strong>. I used the same logic as tutorial hello world code. </div> <div> </div> <div>My JSP is located in Oracle Apps and its powered by Oracle Apache server. I would appreciate if you can give me an approach or point me to an example, to resolve this issue. I have to generate a PDF of some data available to me in the session. I am even ok with the approach of creating a temp.pdf on the server for every user , I can open a file to display it to the user, delete it when he closes the pdf, if so how do i do? any examples available? i tried searching the archives could not come across the one i need. Thanks for your help in advance. I need to get through the first step, and I am sure everything else will be easy after, I wanna generate a pdf from Helloworld.jsp.</div> <div> </div> <div>Here is my code -- helloworld.jsp- same as what is available in the itext tutorial</div> <div> </div> <div> <p><%@ page import="java.io.*"%><br><%@ page import=" ;com.lowagie.text.*"%><br><%@ page import="com.lowagie.text.pdf. *"%></p> <p><br><%<br>try{<br>response.setContentType("application/pdf"); <br>Document doc = new Document();<br>java.io.ByteArrayOutputStream .html>java.io.ByteArrayOutputStream java.io.ByteArrayOutputStream .java.html> ' border=0> buffer = new java.io.ByteArrayOutputStream .html>java.io.ByteArrayOutputStream java.io.ByteArrayOutputStream .java.html> ' border=0>();<br>PdfWriter.getInstance(doc, buffer); <br>doc.open();<br>doc.add(new Paragraph("Hello World"));<br>java.io .DataOutput ot = new java.io.DataOutputStream (response.getOutputStream());<br >byte[] bytes = buffer.toByteArray();<br>response.setContentLength (bytes.length + 100);<br>for( int i = 0; i < bytes.length; i++ ) {ot .writeByte( bytes[i] ); }<br>doc.close();</p> <p>}</p> <p>catch(Exception e){<br>e.printStackTrace();<br>}</p> <p>%></p></div>
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV __ ____ ____ ____ ____ ____ ____ ____ ____ ____ iText-questions mailing list iText-questions@(protected) https://lists.sourceforge.net/lists/listinfo/itext-questions
|
|
 |