Return to the Alphabetic Index
Return to the Class Browser
Return to the Picture Browser
Copyright (c) 1994 by NeXT Computer, Inc. All Rights Reserved.


Inherits From: NSObject

Conforms To: NSObject (NSObject)

Declared In: AppKit/NSPrintOperation.h

Class Description

NSPrintOperation controls operations that generate Encapsulated PostScript (EPS) code or PostScript print jobs. Generally, EPS code is used to transfer images between applications, which happens when the user copies and pastes graphics, uses a Service, or uses ObjectLinks. PostScript print jobs are generated when the user prints and faxes documents. An NSPrintOperation does not generate PostScript code itself; it just controls the overall process, relying on an NSView object to generate the actual code.

NSPrintOperation relies mainly on two other objects: an NSPrintInfo object, which specifies how the code should be generated, and an NSView object, which performs the actual code generation. You specify these two objects in the method you use to create the NSPrintOperation. If no NSPrintInfo is specified, NSPrintOperation uses the shared NSPrintInfo, which contains default values. The shared NSPrintInfo works well for applications that are not document-based. Document-based applications should create an NSPrintInfo for each document that might be printed or copied and use that object instead.

You should create an NSPrintOperation in any method that is invoked when a user executes a Print command or a Copy command. That method also must send NSPrintOperation a runOperation message to start the operation. A print: method for a document-based application might look like this:

- (void)print:sender {

[[NSPrintOperation printOperationWithView:[self myView] printInfo:[document

docPrintInfo]] runOperation];


This method creates an NSPrintOperation for a print job that uses the document's NSPrintInfo. Because this is a print job, a Print panel (NSPrintPanel object) is displayed to allow the user to select printing options. The NSPrintOperation copies the NSPrintInfo, updates this copy with information from the Print panel, and uses the specified NSView to perform the operation.

The information stored in an NSPrintInfo that's retained between operations is information that's likely to remain constant for a document, such as its page size. All information that's likely to change between operations is set to a default value in the NSPrintInfo before the operation begins. In this way, even though NSPrintOperation updates the NSPrintInfo with information from the Print panel for print jobs, that information is reset back to the default values for each print job. Because NSPrintOperation keeps a copy of the NSPrintInfo it uses, you could duplicate a specific print job by storing that copy and reusing it.

Creating and Initializing an NSPrintOperation Object

Setting the Print Operation

Determining the Type of Operation

Controlling the User Interface

Managing the DPS Context

Page Information

Running a Print Operation

Getting the NSPrintInfo Object

Getting the NSView Object