File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Print Friendly presentation with servlets or JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Print Friendly presentation with servlets or JSP" Watch "Print Friendly presentation with servlets or JSP" New topic

Print Friendly presentation with servlets or JSP

J You

Joined: Jul 31, 2001
Posts: 29
I am wondering what will be a good solution in such a sceanario:
you use Java Servlets/JSP to retrieve data from database and
present them in a table,like most applications do. The table
will contain 100 rows,and you are permitted to present the
table in one homepage like below:
Table Title
This is a easy work.
But you boss also want to print this table,i.e,there
is a button in the page and when he press it,the table
will get printed with his printer,also,the printed
table should be in a "nice" format: 25 rows per page,
and there is a 'title' header in every page.
So,what is your opinion?
I don't think there is instant solution here,
the problems are:
1,how the client side script start the printer job?Maybe
need a standalone client application?
2,how to generate the "printer friendly" pages?
Maybe,it is better to transform the table to a .PDF file so
the client can print it with Acrobat Reader?Is there any
XXX2PDF package there?
I am just very intereted in this problem and hope to find
a way to deal with it.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

To get the maximum control over the appearance of the page without having to fight Java security, it's easiest to produce the report as a PDF. I've used the "retepPDF" package quite successfully. It's now named "gnujpdf" available at
One caution, though. If you write the PDF straight to the HTTP output stream, many appservers won't set the content-length header, which will cause Netscape to be fail to display the page. One way to solve that is to write the PDF to a temp file, get its length, send the header, then copy the temp file to the HTTP output stream, and finally delete the temp file.

An IDE is no substitute for an Intelligent Developer.
Kim MacKellar

Joined: Aug 14, 2001
Posts: 4
Does this PDF package use the AWT? Meaning if I'm running a servlet on a server that doesn't have XWindows or Windows will this work?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

It does seem to want to have a graphics environment to link to. I think it may be getting its font metrics from there, based on some recent messages I seen go across the log. They tried to base it on the Java rendering API.
There are also several commercial PDF Java packages out there.
Tim Lauster

Joined: Jul 09, 2001
Posts: 19
Do you have the names of some commercial JAVA PDF packages?
Have you used any of them? Is there one that you recommend?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

I got by with the retepPDF package, so I don't have any experience with the commercial ones. I see them advertised in Java-related magazines, though. You could also search the Web.
Manjunath Reddy
Ranch Hand

Joined: Jul 26, 2001
Posts: 60
You might want to look at the FOP(print formatting objects) from Its freeware and uses xsl to transform XML documents to professional pdf. one can produce amazing pdf's with tables, images and charts with the FOP objects. To get started check out the following article.
subject: Print Friendly presentation with servlets or JSP
jQuery in Action, 3rd edition