• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use printer using java lang?

 
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about PrinterJob class?
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic