0

当使用 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()
}
4

1 回答 1

0

我最终解决了这个问题,NSPrintInfo.paperSize采用 POINTS 而不是 PIXELS,所以我从毫米到像素的计算不正确(打印机设置以毫米为单位,而不是像素或点)。

如果有人感兴趣,从毫米到点的数学计算是;

millimetres * 72 / 25.4
于 2016-06-02T09:02:12.363 回答