Java Mailing List Archive

http://www.junlu.com/

Google
Google
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
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
PDF From JSP page - Some Urgent help needed

PDF From JSP page - Some Urgent help needed

2006-07-20       - By Satish

 Back
Reply:     1     2     3  

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 Source code of java.io.ByteArrayOutputStream.html>java.io.ByteArrayOutputStream Source code of java.io.ByteArrayOutputStream java.io.ByteArrayOutputStream Source code of java.io.ByteArrayOutputStream.java.html>Source code of <a href=http://www.docjar.com/docs/api/java/io/ByteArrayOutputStream.html>java.io.ByteArrayOutputStream</a> <a href=http://www.docjar.com/html/api/java/io/ByteArrayOutputStream.java.html><img src=/j.gif alt=' border=0> buffer = new java.io.ByteArrayOutputStream Source code of java.io.ByteArrayOutputStream.html>java.io.ByteArrayOutputStream Source code of java.io.ByteArrayOutputStream java.io.ByteArrayOutputStream Source code of java.io.ByteArrayOutputStream.java.html>Source code of <a href=http://www.docjar.com/docs/api/java/io/ByteArrayOutputStream.html>java.io.ByteArrayOutputStream</a> <a href=http://www.docjar.com/html/api/java/io/ByteArrayOutputStream.java.html><img src=/j.gif alt=' border=0>();
PdfWriter.getInstance(doc, buffer);
doc.open();
doc.add(new Paragraph("Hello World"));
java.io.DataOutput Source code of java.io.DataOutput ot = new java.io.DataOutput Source code of java.io.DataOutputStream(
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>&nbsp;</div>
<div>Thanks for the sample code, I got it, now I have started running into
problems.</div>
<div>&nbsp;</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>&nbsp;</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>&nbsp;</div>
<div><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; File name does not begin with %PDF-</strong></div>
<div><br>But in FireFox its just a blank screen.</div>
<div>&nbsp;</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>&nbsp;</div>
<div>My JSP is&nbsp;located in Oracle Apps and its powered&nbsp;by Oracle
Apache server. I would appreciate if you can give me an approach or point me to
an example,&nbsp;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&nbsp;every user&nbsp;, I can open&nbsp;a file to
display&nbsp;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>&nbsp;</div>
<div>Here is my code -- helloworld.jsp- same as what is available in the itext
tutorial</div>
<div>&nbsp;</div>
<div>
<p>&lt;%@ page import=&quot;java.io.*&quot;%&gt;<br>&lt;%@ page import=&quot
;com.lowagie.text.*&quot;%&gt;<br>&lt;%@ page import=&quot;com.lowagie.text.pdf.
*&quot;%&gt;</p>
<p><br>&lt;%<br>try{<br>response.setContentType(&quot;application/pdf&quot;);
<br>Document doc = new Document();<br>java.io.ByteArrayOutputStream Source code of java.io.ByteArrayOutputStream.html>java.io.ByteArrayOutputStream Source code of java.io.ByteArrayOutputStream java.io.ByteArrayOutputStream Source code of java.io.ByteArrayOutputStream.java.html>Source code of <a href=http://www.docjar.com/docs/api/java/io/ByteArrayOutputStream.html>java.io.ByteArrayOutputStream</a> <a href=http://www.docjar.com/html/api/java/io/ByteArrayOutputStream.java.html><img src=/j.gif alt=' border=0> buffer = new
java.io.ByteArrayOutputStream Source code of java.io.ByteArrayOutputStream.html>java.io.ByteArrayOutputStream Source code of java.io.ByteArrayOutputStream java.io.ByteArrayOutputStream Source code of java.io.ByteArrayOutputStream.java.html>Source code of <a href=http://www.docjar.com/docs/api/java/io/ByteArrayOutputStream.html>java.io.ByteArrayOutputStream</a> <a href=http://www.docjar.com/html/api/java/io/ByteArrayOutputStream.java.html><img src=/j.gif alt=' border=0>();<br>PdfWriter.getInstance(doc, buffer);
<br>doc.open();<br>doc.add(new Paragraph(&quot;Hello World&quot;));<br>java.io
.DataOutput ot = new java.io.DataOutputStream Source code of java.io.DataOutputStream(response.getOutputStream());<br
>byte[] bytes = buffer.toByteArray();<br>response.setContentLength
(bytes.length + 100);<br>for( int i = 0; i &lt; bytes.length; i++ ) {ot
.writeByte( bytes[i] ); }<br>doc.close();</p>
<p>}</p>
<p>catch(Exception e){<br>e.printStackTrace();<br>}</p>
<p>%&gt;</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

©2008 junlu.com - Jax Systems, LLC, U.S.A.