This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Print Friendly presentation with servlets or JSP" Watch "Print Friendly presentation with servlets or JSP" New topic
Author

Print Friendly presentation with servlets or JSP

J You
Greenhorn

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: 15951
    
  19

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 http://www.sourceforge.net
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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Kim MacKellar
Greenhorn

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: 15951
    
  19

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
Greenhorn

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?
Thanks.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951
    
  19

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 xml.apache.org. 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.
http://www.planet-source-code.com/xq/ASP/txtCodeId.2182/lngWId.2/qx/vb/scripts/ShowCode.htm
cheers,
mpr
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Print Friendly presentation with servlets or JSP
 
Similar Threads
How to get the printer friendly version of a JSP
printer friendly page
Problem in print printer friendly version
Print Preview is different from jsp page displayed
forwarding data to printer friendly page