Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSPrintOperation

Inherits from
Package
com.apple.cocoa.application
Companion guide

Overview

An NSPrintOperation object controls operations that generate Encapsulated PostScript (EPS) code, Portable Document Format (PDF) code, or print jobs. NSPrintOperation works in conjunction with two other objects: an NSPrintInfo object, which specifies how the code should be generated, and an NSView object, which generates the actual code.

It is important to note that the majority of methods in NSPrintOperation copy the instance of NSPrintInfo passed into them. Future changes to that print info are not reflected in the print info retained by NSPrintOperation. All changes should be made to the print info before passing to NSPrintOperation methods. The only method in NSPrintOperation which does not copy the NSPrintInfo instance is setPrintInfo.

Tasks

Constructors

Creating an NSPrintOperation

Setting the Current NSPrintOperation for This Thread

Determining the Type of Operation

Modifying the NSPrintInfo Object

Getting the NSView Object

Running a Print Operation

Modifying the User Interface

Managing the Drawing Context

Modifying Page Information

Managing Printing Threads

Constructors

NSPrintOperation

Creates an empty NSPrintOperation.

public NSPrintOperation()

Static Methods

currentOperation

Returns the current print operation for this thread.

public static NSPrintOperation currentOperation()

Discussion

Returns null if there isn’t a current operation.

See Also

EPSOperationWithViewInsideRect

Returns a new NSPrintOperation object that controls the copying of EPS graphics from the area specified by rect in aView.

public static NSPrintOperation EPSOperationWithViewInsideRect(NSView aView, NSRect rect, NSMutableData data)

Discussion

The new NSPrintOperation object uses the default NSPrintInfo object. The EPS code is written to data. Throws an exception if there is already a print operation in progress; otherwise the returned object is made the current print operation for this thread.

Returns a new NSPrintOperation object that controls the copying of EPS graphics from the area specified by rect in aView.

public static NSPrintOperation EPSOperationWithViewInsideRect(NSView aView, NSRect rect, NSMutableData data, NSPrintInfo aPrintInfo)

Discussion

The new NSPrintOperation object uses the settings stored in aPrintInfo. The code is written to data. Throws an exception if there is already a print operation in progress; otherwise the returned object is made the current print operation for this thread.

Creates and returns a new NSPrintOperation object that controls the copying of EPS graphics from the area specified by rect in aView.

public static NSPrintOperation EPSOperationWithViewInsideRect(NSView aView, NSRect rect, String path, NSPrintInfo aPrintInfo)

Discussion

The new NSPrintOperation object uses the settings stored in aPrintInfo. The code is written to path. Throws an exception if there is already a print operation in progress; otherwise the returned object is made the current print operation for this thread.

PDFOperationWithViewInsideRect

Returns a new NSPrintOperation object that controls the copying of PDF graphics from the area specified by rect in aView.

public static NSPrintOperation PDFOperationWithViewInsideRect(NSView aView, NSRect rect, NSMutableData data)

Discussion

The new NSPrintOperation object uses the default NSPrintInfo object. The PDF is written to data. Throws an exception if there is already a print operation in progress; otherwise the returned object is made the current print operation for this thread.

Returns a new NSPrintOperation object that controls the copying of PDF graphics from the area specified by rect in aView.

public static NSPrintOperation PDFOperationWithViewInsideRect(NSView aView, NSRect rect, NSMutableData data, NSPrintInfo aPrintInfo)

Discussion

The new NSPrintOperation object uses the settings stored in aPrintInfo. The PDF is written to data. Throws an exception if there is already a print operation in progress; otherwise the returned object is made the current print operation for this thread.

Creates and returns a new NSPrintOperation object that controls the copying of PDF graphics from the area specified by rect in aView.

public static NSPrintOperation PDFOperationWithViewInsideRect(NSView aView, NSRect rect, String path, NSPrintInfo aPrintInfo)

Discussion

The new NSPrintOperation object uses the settings stored in aPrintInfo. The PDF is written to path. Throws an exception if there is already a print operation in progress; otherwise the returned object is made the current print operation for this thread.

printOperationWithView

Returns a new NSPrintOperation that controls the printing of aView.

public static NSPrintOperation printOperationWithView(NSView aView)

Discussion

The new NSPrintOperation object uses the settings stored in the shared NSPrintInfo object. Throws an exception if there is already a print operation in progress; otherwise the returned object is made the current print operation for this thread.

Returns a new NSPrintOperation that controls the printing of aView.

public static NSPrintOperation printOperationWithView(NSView aView, NSPrintInfo aPrintInfo)

Discussion

The new NSPrintOperation object uses the settings stored in aPrintInfo. Throws an exception if there is already a print operation in progress; otherwise the returned object is made the current print operation for this thread.

setCurrentOperation

Sets the current print operation for this thread to operation.

public static void setCurrentOperation(NSPrintOperation operation)

Discussion

If operation is null, then there is no current print operation.

See Also

Instance Methods

accessoryView

Returns the accessory view used by the receiver’s NSPrintPanel object.

public NSView accessoryView()

Discussion

You use setAccessoryView to customize the default NSPrintPanel object without having to subclass NSPrintPanel or specify your own NSPrintPanel object.

See Also

canSpawnSeparateThread

Returns whether the receiver is allowed to spawn a separate printing thread.

public boolean canSpawnSeparateThread()

See Also

cleanUpOperation

Invoked by runOperation at the end of an operation to remove the receiver as the current operation.

public void cleanUpOperation()

Discussion

You typically do not invoke this method directly.

context

Returns the receiver’s display context used for generating output.

public NSGraphicsContext context()

See Also

createContext

Creates the display context for output generation, using the receiver’s NSPrintInfo settings.

public NSGraphicsContext createContext()

Discussion

Do not invoke this method directly—it is invoked before any output is generated.

See Also

currentPage

Returns the page number of the page currently being printed.

public int currentPage()

See Also

deliverResult

Delivers the results generated by runOperation to the intended destination (for example, the printer spool or preview application).

public boolean deliverResult()

Discussion

Returns true if the operation was successful, false otherwise. Do not invoke this method directly—it is invoked automatically when the operation is done generating the output.

destroyContext

Destroys the receiver’s display context.

public void destroyContext()

Discussion

Do not invoke this method directly—it is invoked at the end of a print operation.

See Also

isCopyingOperation

Returns true if the receiver is an EPS or PDF copy operation.

public boolean isCopyingOperation()

isEPSOperation

Returns true if the receiver controls an EPS operation (initiated by a copy command), and false if the receiver controls a printing operation (initiated by a print command).

public boolean isEPSOperation()

jobStyleHint

Returns the type of content that the print job is printing.

public String jobStyleHint()

Discussion

Returns null if no job style hint has been set.

Availability
See Also

pageOrder

Returns the order in which pages will be printed.

public int pageOrder()

Discussion

See “Constants” for possible return values.

See Also

printInfo

Returns the receiver’s NSPrintInfo object.

public NSPrintInfo printInfo()

See Also

printPanel

Returns the NSPrintPanel object used when running the operation.

public NSPrintPanel printPanel()

See Also

runModalOperation

Runs the print operation, with document-modal sheets attached to docWindow. When the modal session ends, if neither delegate or didRunSelector are null, didRunSelector is sent to delegate with contextInfo as an argument. The

public void runModalOperation(NSWindow docWindow, Object delegate, NSSelector didRunSelector, Object contextInfo)

Discussion

didRunSelector argument must have the following signature:

public void printOperationDidRun(NSPrintOperation printOperation,  boolean success, void  contextInfo)

The value of success is true if the print operation ran to completion without cancellation or error, and false otherwise.

If you send setCanSpawnSeparateThread to an NSPrintOperation object with an argument of true, then the delegate specified in a subsequent invocation of runModalOperation may be messaged in that spawned, non-main thread.

runOperation

Runs the operation, either copying an EPS or PDF graphic or printing a job.

public boolean runOperation()

Discussion

Returns true if successful, false otherwise. The operation runs to completion in the current thread, blocking the application. A separate thread is not spawned, even if canSpawnSeparateThread is true. Use runModalOperation to use document-modal sheets and to allow a separate thread to perform the operation.

See Also

setAccessoryView

Sets the custom accessory view aView, to be used by the receiver’s NSPrintPanel object.

public void setAccessoryView(NSView aView)

Discussion

By using this method you do not need to subclass NSPrintPanel or specify your own NSPrintPanel object. The NSPrintPanel is automatically resized to accommodate the new accessory view aView.

See Also

setCanSpawnSeparateThread

Sets whether the receiver is allowed to spawn a separate printing thread.

public void setCanSpawnSeparateThread(boolean canSpawnSeparateThread)

Discussion

If canSpawnSeparateThread is true, an NSThread is detached when the print panel is dismissed (or immediately, if the panel is not to be displayed). The new thread performs the print operation, so that control can return to your application. A thread is detached only if the print operation is run using runModalOperation. If canSpawnSeparateThread is false, the operation runs on the current thread, blocking the application until the operation completes.

If you send setCanSpawnSeparateThread to an NSPrintOperation object with an argument of true, then the delegate specified in a subsequent invocation of runModalOperation may be messaged in that spawned, non-main thread.

See Also

setJobStyleHint

Sets the type of content that the print job is printing.

public void setJobStyleHint(String hint)

Discussion

This controls the set of items that appear in the Presets menu of the simplified Print panel interface presented by this operation, if it presents one. The supported job style hints are described in the “Constants” section of NSPrintPanel. If hint is null, the standard interface is used.

Availability
See Also

setPageOrder

Sets the order in which pages will be printed to order.

public void setPageOrder(int order)

Discussion

order is one of the values described in “Constants.”

See Also

setPrintInfo

Sets the receiver’s NSPrintInfo object to aPrintInfo.

public void setPrintInfo(NSPrintInfo aPrintInfo)

See Also

setPrintPanel

Sets the receiver’s NSPrintPanel used in the operation to panel.

public void setPrintPanel(NSPrintPanel panel)

See Also

setShowPanels

public void setShowPanels(boolean flag)

Discussion

If flag is true then the receiver’s NSPrintPanel will be used in the operation; otherwise it will not. This method also affects whether a progress panel is presented while the operation runs. If an EPS or PDF copy operation is being performed, neither panel is displayed, regardless of the value of flag.

See Also

setShowsPrintPanel

If flag is true, then the receiver’s NSPrintPanel is used in the operation; otherwise, it is not.

public void setShowsPrintPanel(boolean flag)

Discussion

This method does not affect the display of a progress panel; that operation is now controlled by setShowsProgressPanel.

If an EPS or PDF copy operation is being performed, an NSPrintPanel is not displayed, regardless of the value of flag.

Availability
See Also

setShowsProgressPanel

If flag is true, then the receiver’s progress panel is used in the operation; otherwise, it is not.

public void setShowsProgressPanel(boolean flag)

Discussion

This method does not affect the display of a print panel; that operation is now controlled by setShowsPrintPanel. This method replaces the setShowPanels method.

Availability
See Also

showPanels

Returns true if the NSPrintPanel will be used in the operation, otherwise false.

public boolean showPanels()

See Also

showsPrintPanel

Returns true if the NSPrintPanel will be used in the operation, otherwise false.

public boolean showsPrintPanel()

Availability
See Also

showsProgressPanel

Returns true if a progress panel will be used in the operation, otherwise false.

public boolean showsProgressPanel()

Availability
See Also

view

Returns the NSView object that generates the actual PostScript or PDF code controlled by the receiver.

public NSView view()

Constants

These constants specify the page order. They’re used by pageOrder and setPageOrder.

Constant

Description

AscendingPageOrder

Ascending (back to front) page order.

DescendingPageOrder

Descending (front to back) page order.

SpecialPageOrder

The spooler does not rearrange pages—they are printed in the order received by the spooler.

UnknownPageOrder

No page order specified.



Next Page > Hide TOC


© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-01)


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.