Developer Documentation
PATH  Mac OS X Documentation > Application Kit Reference: Java


[Previous] [Class List] [Next]

NSPrintOperation


Inherits from: NSObject
Package: com.apple.yellow.application


Class Description


An NSPrintOperation object 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 is generated when the user prints and faxes documents. An NSPrintOperation object does not generate PostScript code itself; it just controls the overall process, relying on an NSView object to generate the actual code.

NSPrintOperation works in conjunction with 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 an NSPrintOperation object. If no NSPrintInfo is specified, NSPrintOperation uses the shared NSPrintInfo, which contains default values. (A shared NSPrintInfo object is automatically created for an application.) The shared NSPrintInfo works well for applications that are not document-based. However, document-based applications should create an NSPrintInfo for each document that might be printed or copied and use that object instead. This will allow users to set printing attributes on a per-document basis.

You create NSPrintOperation objects in any method that is invoked when a user chooses a Print or Copy command. That method must also send runOperation to the NSPrintOperation object to start the actual operation.

When repeating a print job, you can suppress the display of the NSPrintPanel object by sending setShowPanels, passing false as the argument, to the NSPrintOperation object before sending it runOperation. However, make sure that any non-default settings in the NSPrintInfo object that would normally be selected from a NSPrintPanel object are set to reasonable values-a copy of an NSPrintInfo object used in a previous print job will have the correct values.

You can also customize the NSPrintPanel object using the setAccessoryView method or specify your own NSPrintPanel object using setPrintPanel (an OpenStep addition).

If you want the PostScript code generated for EPS and printing to be the same but different from the code generated for the screen, you can test for this case by sending isDrawingToScreen to the current NSDPSContext.

If you want to generate different PostScript code when printing vs. creating EPS, you can test for this case by sending isEPSOperation to the current operation.


Constants

These constants specify the page order. They're used by pageOrder and setPageOrder.
Order Meaning
AscendingPageOrder Ascending (back to front) page order.
DescendingPageOrder Descending (front to back) page order.
SpecialPageOrder The spooler will not rearrange pages-they are print in the order received by the spooler.
UnknownPageOrder No page order specified.

Method Types


Creating an NSPrintOperation
EPSOperationWithView:insideRect:toData:
EPSOperationWithView:insideRect:toData:printInfo:
EPSOperationWithView:insideRect:toPath:printInfo:
printOperationWithView:
printOperationWithView:printInfo:
initEPSOperationWithView:insideRect:toData:printInfo:
initWithView:printInfo:
Setting the current NSPrintOperation for this thread
currentOperation
setCurrentOperation
Determining the type of operation
isEPSOperation
Modifying the NSPrintInfo object
printInfo
setPrintInfo
Getting the NSView object
view
Running a print operation
runOperation
cleanUpOperation
deliverResult
Modifying the user interface
showPanels
setShowPanels
accessoryView
setAccessoryView
printPanel
setPrintPanel
Managing the DPS context
context
createContext
destroyContext
Modifying page information
currentPage
pageOrder
setPageOrder

Constructors


NSPrintOperation

public NSPrintOperation(NSView aView, NSPrintInfo aPrintInfo)

Initializes and returns a newly allocated NSPrintOperation object to control the printing of aView, using the settings stored in aPrintInfo. This method makes a copy of aPrintInfo -aPrintInfo is not used in the actual operation.

See Also: - initEPSOperationWithView:insideRect:toData:printInfo:

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

Initializes and returns a newly allocated NSPrintOperation object to control the copying of EPS graphics from the area specified by rect in aView, using the settings stored in aPrintInfo. This method makes a copy of aPrintInfo -aPrintInfo is not used in the actual operation. The EPS code is written to data.

Static Methods


EPSOperationWithViewInsideRect

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

Returns a new NSPrintOperation object that controls the copying of EPS graphics from the area specified by rect in aView. The new NSPrintOperation object will use 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.

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

Returns a new NSPrintOperation object that controls the copying of EPS graphics from the area specified by rect in aView. The new NSPrintOperation object will use 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.

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

Creates and returns a new NSPrintOperation object that controls the copying of EPS graphics from the area specified by rect in aView. The new NSPrintOperation object will use 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.

currentOperation

public static NSPrintOperation currentOperation()

Returns the current print operation for this thread. Returns null if there isn't a current operation.

See Also: setCurrentOperation


printOperationWithView

public static NSPrintOperation printOperationWithView(NSView aview)

Returns a new NSPrintOperation that controls the printing of aView. The new NSPrintOperation object will use 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.

public static NSPrintOperation printOperationWithView(NSView aView, NSPrintInfo aPrintInfo)

Returns a new NSPrintOperation that controls the printing of aView. The new NSPrintOperation object will use 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.

See Also: + printOperationWithView:


setCurrentOperation

public static void setCurrentOperation(NSPrintOperation operation)

Sets the current print operation for this thread to operation. If operation is null, then there is no current print operation.

See Also: currentOperation




Instance Methods



accessoryView

public NSView accessoryView()

Returns the accessory view used by the NSPrintPanel object. You use setAccessoryView to customize the default NSPrintPanel object without having to subclass NSPrintPanel or specify your own NSPrintPanel object.

See Also: printPanel, setPrintPanel, setShowPanels, showPanels



cleanUpOperation

public void cleanUpOperation()

Invoked by runOperation at the end of an operation to remove the receiver as the current operation. You typically do not invoke this method directly.

context

public NSDPSContext context()

Returns the receiver's DPS context used for generating output.

See Also: createContext, destroyContext



createContext

public NSDPSContext createContext()

Creates the DPS context for output generation, using the receiver's NSPrintInfo settings. Do not invoke this method directly-it's invoked before any output is generated.

See Also: context, destroyConte, xt



currentPage

public int currentPage()

Returns the page number of the page currently being printed.

See Also: pageOrder, setPageOrder



deliverResult

public boolean deliverResult()

Delivers the results generated by runOperation to the intended destination (i.e., the printer spool, or preview application). Returns true if the operation was successful, false otherwise. Do not invoke this method directly-it's invoked automatically when the operation is done generating the output.

destroyContext

public void destroyContext()

Destroys the receiver's DPS context. Do not invoke this method directly-it's invoked at the end of a print operation.

See Also: context, createContext



isEPSOperation

public boolean 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).

pageOrder

public int pageOrder()

Returns the order in which pages will be printed. See setPageOrder: for possible return values.

See Also: currentPage



printInfo

public NSPrintInfo printInfo()

Returns the receiver's NSPrintInfo object.

See Also: setPrintInfo



printPanel

public NSPrintPanel printPanel()

Returns the NSPrintPanel object used when running the operation.

See Also: accessoryView, setAccessoryView, setPrintPanel, setShowPanels, showPanels



runOperation

public boolean runOperation()

Runs the operation (i.e., copys an EPS graphic or prints a job). Returns true if successful, false otherwise.

See Also: cleanUpOperation, deliverResult



setAccessoryView

public void setAccessoryView(NSView aView)

Allows you to augment the NSPrintPanel object by adding a custom NSView. 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: accessoryView, printPanel, setPrintPanel, setShowPanels, showPanels



setPageOrder

public void setPageOrder(int order)

Sets the order in which pages will be printed to order. order can be one of the following, described in the Constants secction:

See Also: currentPage, pageOrder



setPrintInfo

public void setPrintInfo(NSPrintInfo aPrintInfo)

Sets the receiver's NSPrintInfo object to aPrintInfo.

See Also: printInfo



setPrintPanel

public void setPrintPanel(NSPrintPanel panel)

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

See Also: accessoryView, printPanel, setAccessoryView, setShowPanels, showPanels



setShowPanels

public void setShowPanels(boolean flag)

If flag is true then the NSPrintPanel will be used in the operation, otherwise it will not.

See Also: accessoryView, printPanel, setAccessoryView">- setAccessoryView, setPrintPanel, showPanels



showPanels

- (BOOL)showPanels

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

See Also: accessoryView, printPanel, setAccessoryView, setPrintPanel, setShowPanels



view

public NSView view()

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


[Previous] [Next]