• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use printer using java lang?

 
sudipto shekhar
Ranch Hand
Posts: 826
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to print a page that is generated. The page is constructed dynamically(using JSP) i.e it contains text as well as data retrived from the database. The retrived data is set into text boxes along with the text.

I can not figure out a method in java to use printer.

What are the arguments that the method will require?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Being generated by a JSP, I assume that you're talking about an HTML page that's displayed in a web browser? If so, then Java won't help you. You can call the JavaScript "window.print()" method, though, which will open a print dialog.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want the users of your web application to print what you're sending them in a JSP, learning how to use Java APIs to print isn't going to help. In web applications, The Java application runs on the server. The clients of your application are using a browser to access it, and they normally wouldn't have any access to printers attached to the server.

If you want the users of your web app to print your page, it is the browser's print function that you must tie into. The easiest way to accomplish this is simply to provide a printer-friendly page, and tell them to click the browser's print button. You can include a button or a link that calls the JavaScript "window.print()" command, but all that does is call the very same API that would be called by the user clicking the browser's print button.
 
sudipto shekhar
Ranch Hand
Posts: 826
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to format printing for each page,that is to be printed,hence want to use java. Any sugtns??
[ April 07, 2008: Message edited by: Sudipto Shekhar ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless people have access to the printer that is set up with the serer, you can not use Java. There is no real way to set up the printer with JavaSceipt. Ifyou are working with IE, you can look into using ActiveX controls.

Eric
 
sudipto shekhar
Ranch Hand
Posts: 826
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about PrinterJob class?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sudipto Shekhar:
What about PrinterJob class?


You are not going to be able to use anything Java related on the server! Everyone keeps telling you that. You would need to use a clientside solution.

Eric
 
sudipto shekhar
Ranch Hand
Posts: 826
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eric Pascarello:


You are not going to be able to use anything Java related on the server!
Eric


Thank You.
 
Yasir Bajwa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to also take a look a print style sheets. Those would be CSS styles applied only for printing, they would be visible to the user in the print preview, and of course printed result
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic