Browse Source

【2025】【菜单栏】文件-压缩,会弹出密码输入框(文档未加密)-修复

lizhe 1 month ago
parent
commit
bc468dab95

+ 5 - 1
PDF Office/PDF Master/AppDelegate+MenuAction.swift

@@ -446,7 +446,11 @@ extension AppDelegate {
     
     @IBAction func menuItemClick_Compress(_ sender: Any) {
         if let mainVC = self.mainViewController() {
-            mainVC.showCompressController(mainVC.listView.document.documentURL)
+            
+            let model = KMBatchProcessingTableViewModel.initWithFilePath(url: mainVC.listView.document.documentURL)
+            model.password = mainVC.listView.document.password ?? ""
+            
+            mainVC.showCompressController(model: model)
         }
     }
     

+ 14 - 6
PDF Office/PDF Master/KMClass/KMPDFViewController/KMMainViewController.swift

@@ -3526,13 +3526,21 @@ struct KMNMWCFlags {
 //MARK: Compress
 extension KMMainViewController {
     func showCompressController(_ url: URL) {
-        KMPasswordInputWindow.openWindow(window: NSWindow.currentWindow(), type: .owner, url: url) { [unowned self] result, password in
-            if (result == .success) {
-                let model = KMBatchProcessingTableViewModel.initWithFilePath(url: listView.document.documentURL)
-                model.password = password ?? ""
-                model.isLock = false
-                self.showCompressController(model: model)
+        let document = CPDFDocument(url:  url)
+        document?.unlock(withPassword: model.password)
+        
+        if !document!.allowsPrinting && !document!.allowsCopying {
+            KMPasswordInputWindow.openWindow(window: NSWindow.currentWindow(), type: .owner, url: url) { [unowned self] result, password in
+                if (result == .success) {
+                    let model = KMBatchProcessingTableViewModel.initWithFilePath(url: listView.document.documentURL)
+                    model.password = password ?? ""
+                    model.isLock = false
+                    self.showCompressController(model: model)
+                }
             }
+        } else {
+            let model = KMBatchProcessingTableViewModel.initWithFilePath(url: listView.document.documentURL)
+            self.showCompressController(model: model)
         }
     }