The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Sarah1 (12) [Avatar] Offline
#1
Hi,

I'm using Jbuilder, Tomcat4.1.

I built a project BSC which used to run your example from the book chapter16/RegisterForm1.java. I run it through the main() method, everything is good, and register_form1.pdf is beautiful.

Then I want to run RegisterForm1.java from JSP.
I created a test.jsp in another project WEBDEV which has very simple 2 lines:
***********************************************************
<%@ page import="bsc.RegisterForm1" %>
<% RegisterForm1.createPdf(); %>.
***********************************************************

When I run my jsp I got the following error:
***********************************************************************************
javax.servlet.ServletException: com.lowagie.text.Rectangle.getLeft(F)F
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:536)
at org.apache.jsp.test_jsp._jspService(test_jsp.java:70)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
........
***********************************************************************************

In BSC I included the iText-2.0.6.jar. I also checked other libraries in WEBDEV, and didn't find any itext.jar files.

why I got this error? Please help. Thanks in advance.

Sarah
blowagie (284) [Avatar] Offline
#2
Re: itext error
Chances are you have an old iText jar in your CLASSPATH somewhere.
Have you tried the getVersion method?
Sarah1 (12) [Avatar] Offline
#3
Re: itext error
Yes, I removed the old iText jar file. Now there is another error nothing related to version.

I directly called createPdf() method of RegisterForm1.java from a JSP.

Now the error message becomes the following:
org.apache.jasper.JasperException: com/lowagie/text/pdf/PdfPCellEvent

RegisterForm1.java implements PdfPCellEvent. Could you tell me why?

Thanks in advance!

Sarah
blowagie (284) [Avatar] Offline
#4
Re: itext error
The exception doesn't tell me much about what is going wrong, but looking at your JSP code, I see you have a newline in the JSP. As you can read in chapter 17, that newline can cause plenty of problems.
Sarah1 (12) [Avatar] Offline
#5
Re: itext error
Thanks for the reply.

What do you mean "a newline in the JSP"? I also didn't find anything related to a newline in chapter 17. Could you tell me what page?

Sarah
blowagie (284) [Avatar] Offline
#6
Re: itext error
It's nothing personal, but people who use JSP to produce binary files either have bad taste or poor judgement. Even when 'required' or 'no other option', I've always refused using JSP to produce PDF. The book has some good advise. It's up to you to follow it, or ignore it. If you ignore it: don't complain smilie

See p547:
If you’re familiar with JSP, you should know that it’s a bad idea to use JSP to generate
binary content. JSP and all the JSP-related technology are good for building
HTML web sites. A JSP file can be also used as a forwarder to a servlet, but it isn’t
recommended to generate a PDF file from a JSP page.
Also on p547:
I can’t repeat it enough: It’s a bad idea to use JSP to generate binary content. I
don’t say it isn’t possible to integrate iText in a JSP page. Surf to http://itext.ugent.-
be:8080/itext-in-action/helloworld.jsp: The link works for me and gives me a PDF
file saying “Hello World,” but it won’t necessarily work for you.
As for the word 'newline', a simple text search in the eBook, would have brought you to p548:
If you copy the JSP example and start working from there, you’ll probably
add indentation, newlines, spaces, carriage returns, and so on. If you’re
used to writing JSPs, it should be second nature to do this. Although this is
good for most of the code you’re writing, it’s forbidden if you want to generate
binary content!

As you're writing JSP, I hope you understand why this is forbidden. If not, also on p548: "JSP pages are compiled to servlets internally." This implies that all whitespace (spaces, newlines, carriage returns, indentation) is taken into account and inserted into the binary file you are producing. That's bad, really bad.

Please use JSP technology for what it's made for. Don't abuse it. You don't eat soup with a fork, do you? Then why produce PDF with JSP? It's the same problem.