Pārlūkot izejas kodu

【综合】数字签名模块,添加图片提示错误信息修改

niehaoyu 9 mēneši atpakaļ
vecāks
revīzija
4534621a25

+ 20 - 8
PDF Office/PDF Master/Class/DigtalSignature/ViewControllers/CDSignatureCertificateCustomViewController.swift

@@ -420,20 +420,24 @@ class CDSignatureCertificateCustomViewController: NSViewController, NSTextFieldD
     @IBAction func buttonItemClick_Browse(_ sender: Any) {
         
         let openPanel = NSOpenPanel()
-        openPanel.canChooseDirectories = true
+        openPanel.canChooseDirectories = false
         openPanel.canChooseFiles = true
         openPanel.allowsMultipleSelection = false;
         openPanel.allowedFileTypes = KMPDFSignatureImageView().supportedImageTypes()
         openPanel.beginSheetModal(for: self.view.window!) { result in
             if result == .OK {
                 let fileURL = openPanel.urls.first
-                let document = CPDFDocument(url: fileURL)
-                if !document!.allowsCopying || !document!.allowsPrinting {
-                    let alert = NSAlert()
-                    alert.alertStyle = .critical
-                    alert.messageText = NSLocalizedString("This is a secured document. Editing is not permitted.", comment: "")
-                    alert.runModal()
-                    return
+                let filePath: String = fileURL!.path
+               
+                if self.isPDFFile(atPath: filePath) == true {
+                    let document = CPDFDocument(url: fileURL)
+                    if !document!.allowsCopying || !document!.allowsPrinting {
+                        let alert = NSAlert()
+                        alert.alertStyle = .critical
+                        alert.messageText = NSLocalizedString("This is a secured document. Editing is not permitted.", comment: "")
+                        alert.runModal()
+                        return
+                    }
                 }
                 
                 self.appearanceData.signatureConfig.text = ""
@@ -722,4 +726,12 @@ class CDSignatureCertificateCustomViewController: NSViewController, NSTextFieldD
         }
     }
     
+    func isPDFFile(atPath path: String) -> Bool {
+        let fileURL = URL(fileURLWithPath: path)
+        if let fileExtension = fileURL.pathExtension.lowercased() as? String {
+            return fileExtension == "pdf"
+        }
+        return false
+    }
+
 }