< Previous PageNext Page > Hide TOC

How Print Information Is Stored

An NSPrintInfo object stores the attributes that describe a print job. A print info object is passed to an NSPrintOperation object, which makes a copy of it to use during an operation. Normally you don’t set NSPrintInfo attributes directly—this is done by instances of NSPageLayout and NSPrintPanel. The NSView that’s being printed may also supersede some NSPrintInfo settings, such as the pagination and orientation attributes.

A shared print info object is automatically created for an application and is used by default for all print jobs for that application if you do not provide your own instance to the NSPrintOperation, NSPageLayout, and NSPrintPanel objects. You can create your own print info object with different default settings and make it the shared instance with the NSPrintInfo class method setSharedPrintInfo:. You get the shared NSPrintInfo object using the sharedPrintInfo class method.

In an NSDocument-based application, each NSDocument has its own print info object, which you can obtain with NSDocument’s printInfo method. Unless you set one yourself, using NSDocument’s setPrintInfo: method, the document initially uses a copy of the application’s shared object. When the user makes changes in the Page Setup panel, the document’s print info object is automatically updated with the new print settings.

An NSPrintInfo object contains a dictionary that stores its attribute settings. The dictionary keys are described in the “Constants” section of NSPrintInfo.

There are a couple cases where you may want to record the settings of a print info object. First, you may want to remember the print settings used the last time your application was run. In this case you could record the print info object as an application preference each time the user prints something and then restore the settings when the application launches. However, because the dictionary that stores an NSPrintInfo object’s print settings includes non-property list values, it is not a proper property list object. Therefore, it cannot be converted to a plist format and saved directly as a preference value. Instead, you need to use the NSKeyedArchiver (or NSArchiver) class method archivedDataWithRootObject: to encode the NSPrintInfo object as an NSData object, which can be stored in a property list or saved to a file. To restore the NSPrintInfo object, reload the NSData object and then use the NSKeyedUnarchiver (or NSUnarchiver) class method unarchiveObjectWithData: to decode the NSPrintInfo information.

The second case of saving print info objects applies to document-based applications. Print settings are often document specific. For example, a user may print a wide spreadsheet in landscape mode. That setting should be remembered each time the document is printed but should not be used for any other documents, which the user may prefer to print in portrait mode.Therefore, each document should have its own print info object that is saved with the document and used each time that particular document is printed. As before, you should encode the NSPrintInfo object into an NSData object. Then, you should write the data to the document’s file.



< Previous PageNext Page > Hide TOC


© 2002, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-06-28)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.