macoscocoaprintingnsoutlineview

How to print an NSOutlineView with NSVIew.printView


I want to print an NSOutlineView. The view is a subview of a window on screen. I noticed the NSView api call printView. So I tried it in a simple minded fashion. In my AppDelegate I have a call:

@IBAction func doPrint(_ sender: Any?) {
    globalOutlineCntrl?.outlineView.printView(self)
}

So with the window containing the outline on-screen, I issued the doPrint call.

The outline on screen looks like this: Screenshot The doPrint call seems to work, but prints this: enter image description here Is there anyway to make this work? If not how else to print a subview outline?


Solution

  • Dark mode causes some issues with printing. The easiest workaround is to create a separate, programmatic view with forced light appearance, clone the required content and then print that view.

    view.appearance = NSAppearance(named: .aqua)