如何在可可,swift中设置打印?

时间:2023-01-24 11:55:40

I have made printing functionality for custom NSView of NSPopover by the assigning the following action to button for this NSView in mainController:

我通过在mainController中为此NSView的按钮分配以下操作,为NSPopover的自定义NSView创建了打印功能:

@IBOutlet var plasmidMapIBOutlet: PlasmidMapView!

@IBAction func actionPrintfMap(sender: AnyObject)
{
    plasmidMapIBOutlet.print(sender)
}

It is working, but the print window has no option for Paper Size and Orientation, see screenshot below. 如何在可可,swift中设置打印?

它工作正常,但打印窗口没有纸张尺寸和方向选项,请参见下面的截图。

  1. What should I do to get these options in the print window?
  2. 如何在打印窗口中获取这些选项?

  3. And, how to make the NSView fitting to the printable area? Now it is not fitting.
  4. 并且,如何使NSView适合可打印区域?现在它不合适。

I have figured out some moments, but not completely. So, I can setup the printing by the following code

我已经想出了一些时刻,但并不完全。所以,我可以通过以下代码设置打印

 @IBAction func actionPrintMap(sender: AnyObject)
 {
    let printInfo = NSPrintInfo.sharedPrintInfo()
    let operation: NSPrintOperation = NSPrintOperation(view: plasmidMapIBOutlet, printInfo: printInfo)
    operation.printPanel.options = NSPrintPanelOptions.ShowsPaperSize
    operation.printPanel.options = NSPrintPanelOptions.ShowsOrientation
    operation.runOperation()

    //plasmidMapIBOutlet.print(sender)
 }

But, I still have problem. From the code above I can get only orientation (the last, ShowsOrientation), but not both PaperSize and Orientation. How can I manage both ShowsPaperSize and ShowsOrientation?

但是,我还有问题。从上面的代码我只能获得方向(最后,ShowsOrientation),但不能同时获得PaperSize和Orientation。如何管理ShowsPaperSize和ShowsOrientation?

1 个解决方案

#1


3  

Finally I have found the answer which is simple to write but it is not really obvious from apple documentation.

最后我找到了答案,这个答案很简单,但从苹果文档来看并不是很明显。

    operation.printPanel.options.insert(NSPrintPanelOptions.showsPaperSize)
    operation.printPanel.options.insert(NSPrintPanelOptions.showsOrientation)

#1


3  

Finally I have found the answer which is simple to write but it is not really obvious from apple documentation.

最后我找到了答案,这个答案很简单,但从苹果文档来看并不是很明显。

    operation.printPanel.options.insert(NSPrintPanelOptions.showsPaperSize)
    operation.printPanel.options.insert(NSPrintPanelOptions.showsOrientation)