我有一个 Swift Cocoa 程序,用于打印 NSView。它在 Monterey 中运行良好,但在 Sonoma 中显示打印面板。我找不到问题所在。以下是 4 个错误:无法连接 (
我有一个 Swift Cocoa 程序,用于打印 NSView。它在 Monterey 中运行良好,但在 Sonoma 中显示打印面板。我找不到问题所在。以下是 4 个错误:
无法将 (genericPrinterImage) 出口从 (PMPrinterSelectionController) 连接到 (NSImageView):缺少 setter 或实例变量
无法将 (otherPrintersLabel) 出口从 (PMPrinterSelectionController) 连接到 (NSTextField):缺少 setter 或实例变量
无法将 (localPrintersLabel) 出口从 (PMPrinterSelectionController) 连接到 (NSTextField):缺少 setter 或实例变量
无法将 (genericPrinterImage) 出口从 (PMPrinterSelectionController) 连接到 (NSImageView):缺少 setter 或实例变量
func createPrintOperation() {
let printOpts: [NSPrintInfo.AttributeKey: Any] = [
.headerAndFooter: false,
.orientation: NSPrintInfo.PaperOrientation.portrait
]
let printInfo = NSPrintInfo(dictionary: printOpts)
printInfo.leftMargin = 0
printInfo.rightMargin = 0
printInfo.topMargin = 0
printInfo.bottomMargin = 0
printInfo.horizontalPagination = .fit
printInfo.verticalPagination = .automatic
printInfo.isHorizontallyCentered = true
printInfo.isVerticallyCentered = true
printInfo.scalingFactor = 1.0
printInfo.paperSize = NSMakeSize(612, 792) // Letter size
// Create a print operation with the view you want to print , myPrintView is a NSView
let printOperation = NSPrintOperation(view: myPrintView, printInfo: printInfo)
// Configure the print panel
printOperation.printPanel.options.insert(NSPrintPanel.Options.showsPaperSize)
printOperation.printPanel.options.insert(NSPrintPanel.Options.showsOrientation)
// Set the job title for the print operation
let jobTitle = fact.nom_complet_f.replacingOccurrences(of: " ", with: "")
printOperation.jobTitle = jobTitle
// Run the print operation
printOperation.run()
}