printing images in java
1 posts in topic
Flat View  Flat View

Posted By:   tispl_tispl
Posted On:   Saturday, April 7, 2001 01:27 AM

how do i print images in java?(i am using an application that has to print the logo followed by text. the logo is in jpg / gif format? Could you please help me.....? send your reply to tispl@satyam.net.in

Re: printing images in java

Posted By:   Michael_Wax  
Posted On:   Sunday, April 8, 2001 01:09 PM

Basic printing under the AWT works like the following:

Toolkit toolkit = Toolkit.getDefaultToolkit();
PrintJob job = toolkit.getPrintJob(parentFrame, jobTitle, jobProperties);
if (job != null) {
//only come here if the user hasn't cancelled the print dialog
Graphics pg = job.getGraphics();
if (pg != null) {

The fields and methods used above are:
  • Frame parentFrame - the parent frame of the print dialog

  • String jobTitle - the name of the print job

  • Properties jobProperties - a properties file with information on the print job, e.g., number of copies

  • paint - could be the same paint method used for display, or could be a different, print-specific method

You probably will need to play with this to make it work optimally, as differences in what you are printing, and the system and printer that you are using, tend to affect the output. In particular, you may need to modify the paint method to ensure that the printed version looks good.

About | Sitemap | Contact