Mac OS X Developer's Guide

Printing in Cocoa (as in MacApp and most other frameworks) is a simple operation for you to implement. At its most basic, you take a view that is displayed and pass it to a method that redraws it for the selected printer. The standard page setup and page layout settings are managed by the framework.
This works for small views where a simple copy of the screen image is sufficient. It breaks down when you want the printed version to be different (with timestamps, for example, or headers and footers that do not appear on the screen). In that case, you create a separate view just for printing and place your data into it. If you have set up your application well, the data (model) and the view are as distinct as possible; as a result, it should be a simple matter to redraw the objects in a new view.
Mac OS X supports PDF print previews. When these are required, you can implement them with a special override if needed.
Although the standard page setup and printing dialogs are usually satisfactory, you can also extend them.
Printing is handled by the NSPrintOperation object. You are responsible for creating it, associating a view with it, and running it.
The simplest form of printing involves overriding the print method of a view. If you do so, printing will just work for that view. Here is the code:
Java:
public void print { (NSPrintOperation.