Forums Register Login

printing in printer friendly format

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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!
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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/
+Pie Number of slices to send: Send
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.

 
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
I found a beautiful pie. And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2806 times.
Similar Threads
Which JSP version I'm using?
array comparison
Your details online
How to assign js variable to jsp variable
disassembler
Specialized printing from a JSP page
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 04:23:14.