aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How to use printer using java lang? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to use printer using java lang?" Watch "How to use printer using java lang?" New topic
Author

How to use printer using java lang?

sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 813

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?


Regards, Sud.
SCJP 5 ScjpFAQ JLS
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39537
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 813

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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Apr 02, 2008
Posts: 813

What about PrinterJob class?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Apr 02, 2008
Posts: 813

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

Joined: May 02, 2007
Posts: 23
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use printer using java lang?
 
Similar Threads
Printing API Question
how to set up custom page set for printer and select printer for script
is there any guide lines for this problem ?
convert javascript array into java array
Java Network printer