As easy as 1, 2, 3...
The goal of this tutorial is to provide you with a high-level understanding of the various Java Print APIs
and to show you how they can be used with jPDF Printer.
Over time, versions of Java Print API have evolved along two quite different directions.
When one uses Java 1.3 the Printer API implementation class is java.awt.PrinterJob .
When one uses Java 1.4 or better the implementation class is javax.print.DocPrintJob .
Many developers know the characteristics of PrinterJob API.
The new Print API offered in JDK 1.4+, however, offers the
following benefits:
- Clean API that is much easier to program.
- Service orientation - as each printer is a print service with its own properties.
- Synchronous and asynchronous printing.
- The raising of events on specific conditions.
- Discovery features to find services that match a certain feature (i.e., find a Postscript Printer).
- Special print attributes such as collating, duplexing, quality, etc...
Programmatically speaking the process remains the same with the two API.
- Creating a printer job, either using static call or a service lookup.
- Prompting the user to pick a physical printer and/or paper format.
- Starting the job request.
- Optionally waiting for completion.
jPDF Printer is one of the six jPDF modules. By
using this particular module, programmers can easily print
PDF documents to their local printers. They can also do format
conversions. Implementations are already available for image graphic
formats such as GIF, JPEG and PNG.
Please note that jPDF Printer is also bundled with
jPDF Viewer (as it can print to local printers) but with a
different licensing agreement. jPDF Printer is to be used to print
documents from servers. If your projects require that you print from thin clients (such as webstart or applets) - you should go with jPDF Viewer.
You can access the PrinterModule via two lines of code:
PdfDocument doc = new PdfDocument("mydocument.pdf");
// Get the printer module:
PrinterModule pm = doc.getPrinterModule();
The PrinterModule then offers the following methods:

You may have noticed that some of the print() methods accept generic objects as parameters.
public void print(Object job) throws PdfException, PrinterException, IOException
public void print(Object job, Object printRequestAttributeSet) throws PdfException, PrinterException, IOException
Since javax.print.DocPrintJob only appeared with JDK 1.4 we
had to use this trick to let our API work with both of the Java
Print API implementations.
The details of the implementation will be explained in the following tutorials:
If you run Java 1.4 or better, please read "Printing with JDK 1.4"
If you run Java 1.3, please read "Printing with JDK 1.3"