printing : Java Glossary
home P words local find no local find frame, full screen Google search web for topic jump to footer translate with Babelfish by Roedy Green ©1996-2008 Canadian Mind Products
Go to : punctuation 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 (all)
printing
There are two kinds of printing: For the rest of this discussion, I will be mostly referring to the second type printing. Within that, there are three different APIs to choose from.

Programmers were not happy with the AWT print interface and Sun has made been several attempts to replace the API. This has mainly lead to confusion. The key is to get clear on just which printing API you are using and stick to it.

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.

In JDK 1.1 unsigned Applets could not print. In more recent versions, they can, though the user has to give an ok.

How To Use PrintJob

For example to print everything in a frame:
In Win95 and NT, the print job properties are ignored. They are system dependent. But here is how Sun implements them:

How To Use PrinterJob

Java 1.2+ PrinterJob is similar to PrintJob. It pops up a platform specific dialog box that the end user fills in to select options.
I don’t know how you go about setting attributes that the end user would otherwise have to select in the dialog.

Attributes

Sun’s Javadoc on the Printing Attributes class : available:

Designing Printouts

Here is a little PostScript grid.ps program.
copy grid.ps lpt1:
(where lpt1: is a PostScript printer) to print out a 1/10" by 1/6" grid on transparent film. It will be useful in designing or checking printouts, especially those on pre-printed forms.

Faster Printing with javax.print

Dot matrix printing is especially slow. To be quick, you must send text intermixed with printer-specific formatting commands. You can do that with RTextPrinter. The following hunk of code presumes you have already, through some other process, created a file file.ps full of PostScript printer commands and you want to get it printed on a printer that can print five double-sided copies on size A4 paper.

Learning More

Sun’s Javadoc on java.awt.PrintJob : available:
Sun’s Javadoc on java.awt.print.PrinterJob : available:
Sun’s JDK Technote Guide on Java Print Service : available:
Sun’s Javadoc on the PrintRequestAttributeSet class : available:
Sun’s Javadoc on the HashPrintRequestAttributeSet class : available:

CMP_homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.16] Visit care2.org
You are visitor number 23,504.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/Mindprod website mirror)
http://mindprod.com/jgloss/printing.html J:\mindprod\jgloss\printing.html