使用NSPrintOperation并将showsPrintPanel设置为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()
}
答案 0 :(得分:0)
我最终解决了这个问题,NSPrintInfo.paperSize占用了POINTS而不是PIXELS,因此我从毫米到像素的计算不正确(打印机设置以毫米为单位,而不是像素或点)。
如果有兴趣,从毫米到点的数学计算是;
millimetres * 72 / 25.4