|
@@ -7,6 +7,7 @@
|
|
|
|
|
|
import Cocoa
|
|
|
import PDFKit
|
|
|
+var sizeController: KMPDFPrintManageWindowController?
|
|
|
|
|
|
typealias KMPrintWindowControllerPrintTypeChange = (_ controller: KMPrintWindowController, _ type: KMPrintModelType) -> Void
|
|
|
|
|
@@ -137,8 +138,10 @@ class KMPrintWindowController: KMBaseWindowController, NetServiceBrowserDelegate
|
|
|
self.bottomView.type = printType
|
|
|
self.settingView.type = printType
|
|
|
}
|
|
|
-
|
|
|
- //MARK: 打开文件
|
|
|
+}
|
|
|
+
|
|
|
+//MARK: 打开文件
|
|
|
+extension KMPrintWindowController {
|
|
|
/**
|
|
|
@abstract 选取文件跳转打印界面
|
|
|
@param window 文档地址
|
|
@@ -197,37 +200,54 @@ class KMPrintWindowController: KMBaseWindowController, NetServiceBrowserDelegate
|
|
|
guard let pdfDocument = PDFDocument(url: inputDocument!.documentURL) else { return }
|
|
|
}
|
|
|
|
|
|
- let printWindowController: KMPrintWindowController = KMPrintWindowController.init(windowNibName: "KMPrintWindowController")
|
|
|
-
|
|
|
- printWindowController.printType = printType
|
|
|
+ guard let pdfDocument = PDFDocument(url: inputDocument!.documentURL) else { return }
|
|
|
switch printType {
|
|
|
case .size:
|
|
|
- printWindowController.window?.contentMinSize = CGSize(width: 600, height: 500)
|
|
|
- printWindowController.window?.contentMaxSize = CGSize(width: 600, height: 500)
|
|
|
- printWindowController.window?.setFrame(NSRect(x: 0, y: 0, width: 600, height: 500), display: true)
|
|
|
- case .poster:
|
|
|
- printWindowController.window?.contentMinSize = CGSize(width: 800, height: 500)
|
|
|
- printWindowController.window?.contentMaxSize = CGSize(width: 800, height: 500)
|
|
|
- printWindowController.window?.setFrame(NSRect(x: 0, y: 0, width: 800, height: 500), display: true)
|
|
|
- case .multipage:
|
|
|
- printWindowController.window?.contentMinSize = CGSize(width: 800, height: 700)
|
|
|
- printWindowController.window?.contentMaxSize = CGSize(width: 800, height: 700)
|
|
|
- printWindowController.window?.setFrame(NSRect(x: 0, y: 0, width: 800, height: 700), display: true)
|
|
|
- case .pamphlet:
|
|
|
- printWindowController.window?.contentMinSize = CGSize(width: 800, height: 600)
|
|
|
- printWindowController.window?.contentMaxSize = CGSize(width: 800, height: 600)
|
|
|
- printWindowController.window?.setFrame(NSRect(x: 0, y: 0, width: 800, height: 600), display: true)
|
|
|
+ sizeController = KMPDFPrintManageWindowController.init(pdfDocument: pdfDocument, currentPage: pdfDocument.page(at: 0)) { document in
|
|
|
+ KMPrintWindowController.openPrintView(document: document)
|
|
|
+ }
|
|
|
+ NSWindow.currentWindow().beginSheet(sizeController!.window!)
|
|
|
+// case .poster:
|
|
|
+//
|
|
|
+// case .multipage:
|
|
|
+//
|
|
|
+// case .pamphlet:
|
|
|
+
|
|
|
default:
|
|
|
break
|
|
|
}
|
|
|
|
|
|
- NSWindow.currentWindow().beginSheet(printWindowController.window!)
|
|
|
- if inputDocument != nil {
|
|
|
- printWindowController.inputDocument = inputDocument
|
|
|
- }
|
|
|
-
|
|
|
- printWindowController.inputType = inputType
|
|
|
- printWindowController.inputPageRange = inputPageRange
|
|
|
+// let printWindowController: KMPrintWindowController = KMPrintWindowController.init(windowNibName: "KMPrintWindowController")
|
|
|
+//
|
|
|
+// printWindowController.printType = printType
|
|
|
+// switch printType {
|
|
|
+// case .size:
|
|
|
+// printWindowController.window?.contentMinSize = CGSize(width: 600, height: 500)
|
|
|
+// printWindowController.window?.contentMaxSize = CGSize(width: 600, height: 500)
|
|
|
+// printWindowController.window?.setFrame(NSRect(x: 0, y: 0, width: 600, height: 500), display: true)
|
|
|
+// case .poster:
|
|
|
+// printWindowController.window?.contentMinSize = CGSize(width: 800, height: 500)
|
|
|
+// printWindowController.window?.contentMaxSize = CGSize(width: 800, height: 500)
|
|
|
+// printWindowController.window?.setFrame(NSRect(x: 0, y: 0, width: 800, height: 500), display: true)
|
|
|
+// case .multipage:
|
|
|
+// printWindowController.window?.contentMinSize = CGSize(width: 800, height: 700)
|
|
|
+// printWindowController.window?.contentMaxSize = CGSize(width: 800, height: 700)
|
|
|
+// printWindowController.window?.setFrame(NSRect(x: 0, y: 0, width: 800, height: 700), display: true)
|
|
|
+// case .pamphlet:
|
|
|
+// printWindowController.window?.contentMinSize = CGSize(width: 800, height: 600)
|
|
|
+// printWindowController.window?.contentMaxSize = CGSize(width: 800, height: 600)
|
|
|
+// printWindowController.window?.setFrame(NSRect(x: 0, y: 0, width: 800, height: 600), display: true)
|
|
|
+// default:
|
|
|
+// break
|
|
|
+// }
|
|
|
+//
|
|
|
+// NSWindow.currentWindow().beginSheet(printWindowController.window!)
|
|
|
+// if inputDocument != nil {
|
|
|
+// printWindowController.inputDocument = inputDocument
|
|
|
+// }
|
|
|
+//
|
|
|
+// printWindowController.inputType = inputType
|
|
|
+// printWindowController.inputPageRange = inputPageRange
|
|
|
}
|
|
|
|
|
|
static func showPrintWindowControll(inputData: URL?, inputDocument: AnyObject?, inputType: DataNavigationViewButtonActionType = .Print, inputPageRange: KMPrintPageRange) {
|
|
@@ -349,7 +369,13 @@ class KMPrintWindowController: KMBaseWindowController, NetServiceBrowserDelegate
|
|
|
printOperation.runModal(for: NSApplication.shared.mainWindow!, delegate: self, didRun: nil, contextInfo: nil)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ static func openPrinter(document: PDFDocument) {
|
|
|
+ let printInfo = NSPrintInfo.shared
|
|
|
+ let printOperation: NSPrintOperation = document.printOperation(for: printInfo, scalingMode: .pageScaleNone, autoRotate: true)!
|
|
|
+ printOperation.showsPrintPanel = true //是否弹出打印机设置界面
|
|
|
+ printOperation.run()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//MARK: - Print
|