打印面板作为工作表视图而不是模态视图

时间:2017-07-23 16:39:05

标签: swift macos cocoa pdf printing

我有这个解决方案用osx打印swift 3的pdf文件。

let dictDocuments = NSURL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])
let completePath = dictDocuments.appendingPathComponent("test.pdf")
let pdfDocument = PDFDocument(url: completePath!)

let printInfoDict = NSMutableDictionary(dictionary: NSPrintInfo.shared().dictionary())
printInfoDict.setObject(NSPrintSpoolJob, forKey: NSPrintJobDisposition as NSCopying)
let printInfo = NSPrintInfo(dictionary: printInfoDict as! [String : Any])

printInfo.isHorizontallyCentered = true
printInfo.isVerticallyCentered = true
printInfo.scalingFactor = 1.5


let printOp = pdfDocument!.printOperation(for: printInfo, scalingMode: .pageScaleNone, autoRotate: true)!

但现在我想将打印对话框显示为工作表视图。

我试过这样的事情:

let printPanel = NSPrintPanel()
printPanel.beginSheet(with: printInfo, modalFor: self.view.window!, delegate: self, didEnd: nil, contextInfo: nil)

打印对话框将显示为工作表视图,但没有pdf文件。 逻辑上:我没有分配pdf文件。但我怎么能这样做?

0 个答案:

没有答案