Rendering to a printer is like rendering to a screen. The printing system controls when pages are rendered, just like the drawing system controls when a component is painted on the screen.
The Java 2D Printing API is based on a callback model in which the printing system, not the application, controls when pages are printed. The application provides the printing system with information about the document to be printed, and the printing system determines when each page needs to be imaged.
The following two features are important to support printing:
When pages need to be imaged, the
printing system calls the application’s print
method with
an appropriate Graphics
context. To use Java 2D API
features when you print, you cast the Graphics
object to a
Graphics2D
class, just like you do when you are rendering to the
screen.