---
title: "printOperation(withSettings:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsdocument/printoperation(withsettings:)"
---

# printOperation(withSettings:)

Creates and returns a print operation for the document’s contents.

## Declaration

```swift
func printOperation(withSettings printSettings: [NSPrintInfo.AttributeKey : Any]) throws -> NSPrintOperation
```

## Parameters

- `printSettings`: The print settings dictionary to use.

## Return Value

Return Value The print operation, or nil if unsuccessful.

## Discussion

Discussion The print operation can be run to print the document’s current contents. The NSPrintInfo attributes in the passed-in printSettings dictionary are added to a copy of the document’s print info, and the resulting print info is used for the operation. important: You must override this method to enable printing in your app. The default implementation raises an exception. note: In Swift, this method is marked with the throws keyword to indicate that it throws an error in cases of failure. When overriding this method, use the throw statement to throw an NSError, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Printing the Document

- [printInfo](appkit/nsdocument/printinfo.md)
- [preparePageLayout(_:)](appkit/nsdocument/preparepagelayout(_:).md)
- [runModalPageLayout(with:delegate:didRun:contextInfo:)](appkit/nsdocument/runmodalpagelayout(with:delegate:didrun:contextinfo:).md)
- [runModalPrintOperation(_:delegate:didRun:contextInfo:)](appkit/nsdocument/runmodalprintoperation(_:delegate:didrun:contextinfo:).md)
- [shouldChangePrintInfo(_:)](appkit/nsdocument/shouldchangeprintinfo(_:).md)
- [print(withSettings:showPrintPanel:delegate:didPrint:contextInfo:)](appkit/nsdocument/print(withsettings:showprintpanel:delegate:didprint:contextinfo:).md)
- [pdfPrintOperation](appkit/nsdocument/pdfprintoperation.md)
- [saveToPDF(_:)](appkit/nsdocument/savetopdf(_:).md)
