• Post Reply Bookmark Topic Watch Topic
  • New Topic

printing in printer friendly format

 
srinivas nama
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have jsp page which loads data dynamically, and I would like to give user option to print only the data....
Help appreciated!!!
thanks
Srinivas Nama
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Printing from a web app can be a little tricky. The web server has no direct connection to your local printer - it's not in the architecture and for security reasons it isn't likely to be added. One trick is to send out a page with a Java applet on it that does the print formatting on the client side, but that's a problem because unsigned applets can't print either, and browser support for applet printing isn't guaranteed.
The easy way is to have the JSP present an alternate "printer-friendly" view, where ONLY the data to be printed is displayed - a lot of webzine sites do this. However, the actual print format cannot be guaranteed, since HTML isn't really designed for absolute page layout - some work has been done there, but it's not well-supported by the current generation of browsers.
You can get a slightly better approach by outputting the data as content-type "text/text" instead of "text/html", but it can still be messy.
So far, if you want absolute page layout control, your best bet is to have a JSP or servlet generate a PDF and let the user's copy of Adobe Acrobat Reader do the printing.
 
Zac Roberts
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reviving this post because I have a similar situation. I am creating an intranet based jsp app which needs to store a list of addresses in a database (I think I will use Cloudscape). Then, with the click of a button, the list needs to be formatted and printed on mailing labels. Needless to say, I need total control of the print layout so I don't waste too many labels. Any ideas of how to do this? I am beginning to think that this is going to get very messy!
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTML printing has too many variable in it for things like label printing. You're at the mercy of not only what web browser you use, but what fonts and printer drivers are installed on the client machine.
For page-oriented absolute-placement printing, output a PDF. If you are looking for something more in the "print a few and tear off" category, create a signed Java applet to run on the client side. It has to be signed to run Java print services.
 
Zac Roberts
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this technology on another forum, anybody used this with success...
Quote: "iText is a library that allows you to generate PDF files on the fly."
http://www.lowagie.com/iText/
 
Bhiku Mhatre
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,
I would like to know how webzines do this. Do they query again to get the printer-friendly view?
Any tricks, tips, links for doing this?
Originally posted by Tim Holloway:

The easy way is to have the JSP present an alternate "printer-friendly" view, where ONLY the data to be printed is displayed - a lot of webzine sites do this.
 
Chris Baron
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know there are css definitions for print media:
http://www.w3schools.com/css/css_mediatypes.asp
http://www.w3schools.com/css/css_ref_print.asp
But i can't tell you how good they work.
 
Bhiku Mhatre
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I think if I really just want to print data and get rid of tables, colors etc, (the way webzines offer pages with no advts and just text/html good for printing)... is CSS the way to go for that? The printer-friendly formats of say onjava.com etc even handle inline images nicely.. so I guess there's something more involved in this, but I am not able to figure out.
Anyone?
 
Wendal Park
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did work with Lowagie's iText, and it's takes quite some time to get familiar with the API to make a decent PDF template.
I have a thought that maybe you can use the <PRE> .... </PRE> preformatted HTML tag to wrap your formatted text in a separate frame, or a new popup window. Then just ask the user to print from there. The good thing about <PRE> tag is that it won't "trim" whitespaces. So simple formatting can be done.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!