<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSDocument/print(withSettings:showPrintPanel:delegate:didPrint:contextInfo:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDocument(im)printDocumentWithSettings:showPrintPanel:delegate:didPrintSelector:contextInfo:"
  },
  "title" : "print(withSettings:showPrintPanel:delegate:didPrint:contextInfo:)"
}
-->

# print(withSettings:showPrintPanel:delegate:didPrint:contextInfo:)

Prints the document’s contents, optionally displaying a print panel to the user.

```
func print(withSettings printSettings: [NSPrintInfo.AttributeKey : Any], showPrintPanel: Bool, delegate: Any?, didPrint didPrintSelector: Selector?, contextInfo: UnsafeMutableRawPointer?)
```

## Parameters

`printSettings`

The print settings dictionary to use.

`showPrintPanel`

A Boolean value indicating whether the print panel is shown.

`delegate`

The delegate to which the selector message is sent.

`didPrintSelector`

The selector of the message sent to the delegate.

`contextInfo`

Object passed with the callback to provide any additional context information.

## Discussion

If showing of the print panel is specified by `showPrintPanel`, the method presents it first and prints only if the user approves the panel. 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 settings are used for the operation. When printing is complete or canceled, the method sends the message selected by `didPrintSelector` to the `delegate`, with the `contextInfo` as the last argument. The method selected by `didPrintSelector` must have the same signature as:

```objc
- (void)document:(NSDocument *)document didPrint:(BOOL)didPrintSuccessfully  contextInfo: (void *)contextInfo
```

The default implementation of this method invokes [`printOperation(withSettings:)`](/documentation/AppKit/NSDocument/printOperation(withSettings:)). If `nil` is returned it presents the error to the user in a document-modal panel before messaging the delegate. Otherwise it invokes `[thePrintOperation setShowsPrintPanel:showPrintPanel]` then `[self runModalPrintOperation:thePrintOperation delegate:delegate didRunSelector:didPrintSelector contextInfo:contextInfo]`.

For backward binary compatibility with OS X v10.3 and earlier, the default implementation of this method invokes [`printShowingPrintPanel:`](/documentation/AppKit/NSDocument/printShowingPrintPanel:) if it is overridden. When doing this it uses private functionality to arrange for the print settings to take effect (despite the fact that the override of [`printShowingPrintPanel:`](/documentation/AppKit/NSDocument/printShowingPrintPanel:) can’t possibly know about them) and to get notified when the print operation has been completed, so it can message the delegate at the correct time. Correct messaging of the delegate is necessary for correct handling of the Print Apple event.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)