Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Print invoice - JSP

 
Kavita Shivani
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

thanks,
Kavitha.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Print on the server or the client?
 
Kavita Shivani
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
on the client side.
 
Ankit Garg
Sheriff
Posts: 9527
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...
 
Kavita Shivani
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone for the response.

Kavitha.
 
Samuel Behrman
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kavita Shivani
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
regards,
Kavitha.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic