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.
Customer surveys are for companies who didn't pay proper attention to begin with.
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!
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.
Joined: Jan 29, 2002
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/
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?
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.