当使用 NSPrintOperation 并将 showPrintPanel 设置为 true 时,视图打印得很好,但是当我将属性设置为 false 时,视图无法正确打印并且比纸张大:
func printBadge(printerName: String){
let printingFrame = NSRect(x: 0, y: 0, width: AppManager.sharedInstance.badge.width, height: AppManager.sharedInstance.badge.height)
let badgeView = BadgeView(frame: printingFrame)
let printOperation = NSPrintOperation(view: badgeView)
let printInfo = printOperation.printInfo
printInfo.printer = NSPrinter(name: printerName)!
printInfo.paperSize = NSSize(width: AppManager.sharedInstance.badge.width, height: AppManager.sharedInstance.badge.height)
printInfo.horizontalPagination = .AutoPagination
printInfo.verticalPagination = .AutoPagination
printInfo.topMargin = 0
printInfo.bottomMargin = 0
printInfo.rightMargin = 0
printInfo.leftMargin = 0
printInfo.horizontallyCentered = true
printInfo.verticallyCentered = true
printOperation.showsPrintPanel = AppManager.sharedInstance.showsPrintPanel!
printOperation.runOperation()
}