Browse Source

【主页】打印入口补充

lizhe 1 year ago
parent
commit
9ef39a4dd3

+ 99 - 0
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController+Action.swift

@@ -162,10 +162,13 @@ extension KMHomeViewController {
         case .equity:
             break
         case .PrintMultipage:
+            self.fastTool_printMultple()
             break
         case .PrintPoster:
+            self.fastTool_printPoster()
             break
         case .PrintBooklet:
+            self.fastTool_printBooklet()
             break
         }
     }
@@ -1656,6 +1659,102 @@ extension KMHomeViewController {
         }
     }
     
+    func fastTool_printBooklet() {
+        let openPanel = NSOpenPanel()
+        openPanel.allowsMultipleSelection = false
+        openPanel.allowedFileTypes = ["pdf"]
+        openPanel.beginSheetModal(for: NSApp.mainWindow!) { result in
+            if result == .cancel {
+                return
+            }
+            
+            if !openPanel.url!.path.isPDFValid() {
+                let alert = NSAlert()
+                alert.alertStyle = .critical
+                alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
+                alert.runModal()
+                return
+            }
+            
+            if let pdf = CPDFDocument(url: openPanel.url!) {
+                if pdf.allowsCopying == false || pdf.allowsPrinting == false {
+                    Task {
+                        _ = await KMAlertTool.runModel(message: KMLocalizedString("This is a secured document. Editing is not permitted.", nil))
+                    }
+                    return
+                }
+            }
+            
+            DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
+                KMPrintWindowController.showNewPrintWindowControll(inputData: openPanel.url, inputDocument: nil, inputPageRange: KMPrintPageRange(), printType: .pamphlet)
+            }
+        }
+    }
+    
+    func fastTool_printPoster() {
+        let openPanel = NSOpenPanel()
+        openPanel.allowsMultipleSelection = false
+        openPanel.allowedFileTypes = ["pdf"]
+        openPanel.beginSheetModal(for: NSApp.mainWindow!) { result in
+            if result == .cancel {
+                return
+            }
+            
+            if !openPanel.url!.path.isPDFValid() {
+                let alert = NSAlert()
+                alert.alertStyle = .critical
+                alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
+                alert.runModal()
+                return
+            }
+            
+            if let pdf = CPDFDocument(url: openPanel.url!) {
+                if pdf.allowsCopying == false || pdf.allowsPrinting == false {
+                    Task {
+                        _ = await KMAlertTool.runModel(message: KMLocalizedString("This is a secured document. Editing is not permitted.", nil))
+                    }
+                    return
+                }
+            }
+            
+            DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
+                KMPrintWindowController.showNewPrintWindowControll(inputData: openPanel.url, inputDocument: nil, inputPageRange: KMPrintPageRange(), printType: .poster)
+            }
+        }
+    }
+    
+    func fastTool_printMultple() {
+        let openPanel = NSOpenPanel()
+        openPanel.allowsMultipleSelection = false
+        openPanel.allowedFileTypes = ["pdf"]
+        openPanel.beginSheetModal(for: NSApp.mainWindow!) { result in
+            if result == .cancel {
+                return
+            }
+            
+            if !openPanel.url!.path.isPDFValid() {
+                let alert = NSAlert()
+                alert.alertStyle = .critical
+                alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
+                alert.runModal()
+                return
+            }
+            
+            if let pdf = CPDFDocument(url: openPanel.url!) {
+                if pdf.allowsCopying == false || pdf.allowsPrinting == false {
+                    Task {
+                        _ = await KMAlertTool.runModel(message: KMLocalizedString("This is a secured document. Editing is not permitted.", nil))
+                    }
+                    return
+                }
+            }
+            
+            DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
+                KMPrintWindowController.showNewPrintWindowControll(inputData: openPanel.url, inputDocument: nil, inputPageRange: KMPrintPageRange(), printType: .multipage)
+            }
+        }
+    }
+    
     
     @IBAction func escButtonAction(_ sender: Any) {
 //        self.historyFileViewController.selectFiles.removeAll()