It's not a secret anymore!
The moose likes HTML, CSS and JavaScript and the fly likes Print invoice - JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Print invoice - JSP" Watch "Print invoice - JSP" New topic

Print invoice - JSP

Kavita Shivani
Ranch Hand

Joined: Aug 14, 2009
Posts: 45
Hi Everyone,
I am working on an application in which, I display an invoice and onclick of the print button, I need to print the invoice. I was suggest to use window.print(); but I am not sure if that is for printing the web page. I just want the Invoice table on my page to be printed without any other HTML things on the page.
Please suggest on how this is done generally.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63870

Print on the server or the client?

[Asking smart questions] [About Bear] [Books by Bear]
Kavita Shivani
Ranch Hand

Joined: Aug 14, 2009
Posts: 45
on the client side.
Ankit Garg

Joined: Aug 03, 2008
Posts: 9466

Once I had such a requirement, so what I did was, give an ID to the specific table to be printed, opened a new window through javascript, put the table (with the ID) as content of the new window and called the print on that new window. I think you can also do that with CSS for printing (a small tutorial here) but I've not used it so not sure. If there is any other simpler way, then I don't know about it ...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Kavita Shivani
Ranch Hand

Joined: Aug 14, 2009
Posts: 45
Thanks everyone for the response.

Samuel Behrman
Ranch Hand

Joined: Oct 02, 2009
Posts: 49
If you have an executing JSP script, can't you just stream the report to
a file or to a printing service like lpr? Then let the print subsystem
deal with printing or transmission over a slow link.

If you're asking for an automagic way of doing this, sorry, I don't know.

Hmm, if you print to RTF, then use a (local) JSP or Java app to remove
all the formatting, images, etc., would you have what you want? Just a
thought. Java does have an HTML/XML parser that would be useful reading
an RTF file, I think.

RAQ Report: Web-based Excel-like Java reporting tool.
Kavita Shivani
Ranch Hand

Joined: Aug 14, 2009
Posts: 45
Thanks Samuel,
Yes I am thinking of something like that for my periodic reports probably I will save the reports in pdf. If I find that easy, I might as well make it same for all sorts of printings in my application.
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
Guessing no one that answered so far realizes there can be different styles sheets that can be added to the document to hide info that you do not want to print/show.

Look into Print Media CSS

I agree. Here's the link:
subject: Print invoice - JSP
It's not a secret anymore!