Last updated 2004-06-28 by Roedy
Green ©1996-2004 Canadian Mind Products
Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
You are here : home : Java Glossary : P words : printing.
The Java 1.0 JDK does not support printing. JDK 1.1 does, via java.awt.PrintJob. You print using the same techniques you use for drawing on the screen. It is much like drawing a high-res screen the size of a sheet of paper. Components now have a print method to print themselves which is usually the same as the one to draw them on the screen. To handle text you use Canvases and drawString, or TextFields. To get properly aligned text without borders, consider the KL-Group components or Swing. Applets cannot print, with one exception, signed Applets running under IE4 in JDK 1.1. For example to print everything in a frame:
PrintJob pj = getToolkit( ).getPrintJob(theFrame, jobTitle, null /* properties */ ); // get Printjob object. Graphics pg = pj.getGraphics(); // get Graphics object for the first page. printAll(pg); // print this component and its subcomponents, at (0,0). pg.dispose(); // release the first page to the print queue. pg = pj.getGraphics(); // get graphics object for second page. pg.drawLine(0, 0, 100, 100 ); // draw directly onto the graphics object as if it were a Canvas. pg.dispose(); // release the second page to the print queue. pj.end(); // Finish off the print job, start printing.
In Win95 and NT, the print job properties are ignored. They are system dependent. But here is how Sun implements them:
howPrint.put( "awt.print.destination", "printer" ); // could be "printer" or "file", default "printer" howPrint.put( "awt.print.fileName", "TEMP/TEMP.PRN" ); // file to receive the PostScript or other physical printer commands howPrint.put( "awt.print.numCopies", "1" ); // default 1 howPrint.put( "awt.print.orientation", "portrait" ); // could be "portrait" or "landscape", default "portrait" howPrint.put( "awt.print.paperSize", "letter" ); // could be "letter","legal","executive " or "a4". default "letter" howPrint.put( "awt.print.printer", "lp" ) // name of command/utility that will do the printing howPrint.put( "awt.print.options", "" ); // options to pass to the print command/utility PrintJob pj = getToolkit().getPrintJob(theFrame, "Print Test #1", howPrint ); Graphics pg = pj.getGraphics(); printAll(pg); pg.dispose(); pj.end();
Here is a little PostScript grid.ps program.
home |
Canadian Mind Products | |||
| mindprod.com IP:[24.87.56.253] | ||||
| Your IP:[80.134.30.163] | ||||
| You are visitor number 3144. | ||||
| Please send errors, omissions and suggestions | ||||
| to improve this page to Roedy Green. | ||||
| You can get a fresh copy of this page from: | or possibly from your local J: drive mirror: | |||
| http://mindprod.com/jgloss/printing.html | J:\mindprod\jgloss\printing.html | |||