瀏覽代碼

Merge branch 'develop_PDFReaderProNew' of git.kdan.cc:Mac_PDF/PDF_Office into develop_PDFReaderProNew

tangchao 1 年之前
父節點
當前提交
3065f37dd8

+ 17 - 9
PDF Office/PDF Master/Class/PDFTools/Compress/Controller/KMCompressWIndowControllerNew.swift

@@ -20,20 +20,28 @@ class KMCompressWIndowControllerNew: NSWindowController {
     
     var documentURL: URL! {
         didSet{
-            KMBaseWindowController.checkPassword(url: documentURL) { [unowned self] success, paasswordString in
-                if success {
-                    self.password = paasswordString
-                    self.compressView.documentURL = self.documentURL
-                } else {
-                    guard let callBack = self.itemClick else { return }
-                    
-                    callBack()
+            if self.password.count != 0 {
+                self.compressView.documentURL = self.documentURL
+            } else {
+                KMBaseWindowController.checkPassword(url: documentURL) { [unowned self] success, paasswordString in
+                    if success {
+                        self.password = paasswordString
+                        self.compressView.documentURL = self.documentURL
+                    } else {
+                        guard let callBack = self.itemClick else { return }
+                        
+                        callBack()
+                    }
                 }
             }
         }
     }
     
-    var password: String!
+    var password: String = "" {
+        didSet {
+            self.compressView.password = password
+        }
+    }
     private var datas: [String] = []
     
     var limit = true

+ 6 - 2
PDF Office/PDF Master/Class/PDFTools/Compress/View/KMCompressView.swift

@@ -41,7 +41,7 @@ class KMCompressView: KMBaseXibView {
             self.reloadData()
         }
     }
-//    var password: String!
+    var password: String = ""
 //    private var datas: [String] = []
 //    var selectIndex = 2
 //    
@@ -93,7 +93,11 @@ class KMCompressView: KMBaseXibView {
                 titleLabel.stringValue = filePath.lastPathComponent
                 finalSizeLabel.isHidden = true
                 
-                let image: NSImage = NSImage.previewForFile(path: url!, ofSize: fileImageView.bounds.size, asIcon: true) ?? NSImage()
+                let pdfDocument = CPDFDocument(url: url)
+                pdfDocument?.unlock(withPassword: self.password)
+                let page = pdfDocument?.page(at: 0) ?? CPDFPage()
+                let image = page.thumbnail(of: page.size)
+//                let image: NSImage = NSImage.previewForFile(path: url!, ofSize: fileImageView.bounds.size, asIcon: true) ?? NSImage()
                 fileImageView.image = image;
             }
         }

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -2087,13 +2087,13 @@ extension KMMainViewController {
         let windowController = KMCompressWIndowControllerNew(windowNibName: "KMCompressWIndowControllerNew")
         self.view.window?.beginSheet(windowController.window!)
         self.currentWindowController = windowController
+        windowController.password = self.listView.document.password
 //        if let _url = url {
 //            windowController.oriDocumentUrl = self.listView.document.documentURL
 //            windowController.documentURL = _url
 //        } else {
             windowController.documentURL = self.listView.document.documentURL
 //        }
-        windowController.password = self.listView.document.password
 
         windowController.itemClick = { [weak self] in
             self?.view.window?.endSheet((self?.currentWindowController.window)!)