Browse Source

ComPDFKit(flutter) - 2.2.2 iOS相关接口和配置补充

yangliuhua 3 weeks ago
parent
commit
f1e343bad2

+ 9 - 9
example/ios/Runner.xcodeproj/project.pbxproj

@@ -489,11 +489,11 @@
 				CLANG_ENABLE_MODULES = YES;
 				CODE_SIGN_IDENTITY = "Apple Development";
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 2.2.1;
+				CURRENT_PROJECT_VERSION = 2.2.2;
 				DEVELOPMENT_TEAM = 4GGQPGRTSV;
 				ENABLE_BITCODE = NO;
-				FLUTTER_BUILD_NAME = 2.2.1;
-				FLUTTER_BUILD_NUMBER = 2.2.1;
+				FLUTTER_BUILD_NAME = 2.2.2;
+				FLUTTER_BUILD_NUMBER = 2.2.2;
 				INFOPLIST_FILE = Runner/Info.plist;
 				IPHONEOS_DEPLOYMENT_TARGET = 12.0;
 				LD_RUNPATH_SEARCH_PATHS = (
@@ -679,11 +679,11 @@
 				CLANG_ENABLE_MODULES = YES;
 				CODE_SIGN_IDENTITY = "Apple Development";
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 2.2.1;
+				CURRENT_PROJECT_VERSION = 2.2.2;
 				DEVELOPMENT_TEAM = 4GGQPGRTSV;
 				ENABLE_BITCODE = NO;
-				FLUTTER_BUILD_NAME = 2.2.1;
-				FLUTTER_BUILD_NUMBER = 2.2.1;
+				FLUTTER_BUILD_NAME = 2.2.2;
+				FLUTTER_BUILD_NUMBER = 2.2.2;
 				INFOPLIST_FILE = Runner/Info.plist;
 				IPHONEOS_DEPLOYMENT_TARGET = 12.0;
 				LD_RUNPATH_SEARCH_PATHS = (
@@ -708,11 +708,11 @@
 				CLANG_ENABLE_MODULES = YES;
 				CODE_SIGN_IDENTITY = "Apple Development";
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 2.2.1;
+				CURRENT_PROJECT_VERSION = 2.2.2;
 				DEVELOPMENT_TEAM = 4GGQPGRTSV;
 				ENABLE_BITCODE = NO;
-				FLUTTER_BUILD_NAME = 2.2.1;
-				FLUTTER_BUILD_NUMBER = 2.2.1;
+				FLUTTER_BUILD_NAME = 2.2.2;
+				FLUTTER_BUILD_NUMBER = 2.2.2;
 				INFOPLIST_FILE = Runner/Info.plist;
 				IPHONEOS_DEPLOYMENT_TARGET = 12.0;
 				LD_RUNPATH_SEARCH_PATHS = (

+ 1 - 1
ios/Classes/CPDFConstants.swift

@@ -1,7 +1,7 @@
 //
 //  CPDFDocumentPlugin.swift
 //  compdfkit_flutter
-//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+//  Copyright © 2014-2025 PDF Technologies, Inc. All Rights Reserved.
 //
 //  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
 //  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.

+ 29 - 26
ios/Classes/ColorHelper.swift

@@ -2,36 +2,39 @@
 //  ColorHelper.swift
 //  compdfkit_flutter
 //
-//  Created by Xiaolong Liu on 2024/7/15.
+//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
 //
-
+//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+//  This notice may not be removed from this file.
 
 import UIKit
 
 class ColorHelper {
     static func colorWithHexString (hex:String) -> UIColor {
         var hexString = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
-                
-                // 检查颜色字符串是否有效
-                if hexString.hasPrefix("#") {
-                    hexString.remove(at: hexString.startIndex)
-                }
-                
-                // 确保字符串长度是8(包括透明度部分)
-                if hexString.count == 8 {
-                    var rgba: UInt64 = 0
-                    Scanner(string: hexString).scanHexInt64(&rgba)
-                    
-                    let a = CGFloat((rgba >> 24) & 0xFF) / 255.0
-                    let r = CGFloat((rgba >> 16) & 0xFF) / 255.0
-                    let g = CGFloat((rgba >> 8) & 0xFF) / 255.0
-                    let b = CGFloat(rgba & 0xFF) / 255.0
-                    
-                    return UIColor(red: r, green: g, blue: b, alpha: a)
-                } else {
-                    // 如果不是合法的8位Hex,返回透明的颜色或其他默认值
-                    return UIColor(white: 0.0, alpha: 0.0)
-                }
+        
+        // 检查颜色字符串是否有效
+        if hexString.hasPrefix("#") {
+            hexString.remove(at: hexString.startIndex)
+        }
+        
+        // 确保字符串长度是8(包括透明度部分)
+        if hexString.count == 8 {
+            var rgba: UInt64 = 0
+            Scanner(string: hexString).scanHexInt64(&rgba)
+            
+            let a = CGFloat((rgba >> 24) & 0xFF) / 255.0
+            let r = CGFloat((rgba >> 16) & 0xFF) / 255.0
+            let g = CGFloat((rgba >> 8) & 0xFF) / 255.0
+            let b = CGFloat(rgba & 0xFF) / 255.0
+            
+            return UIColor(red: r, green: g, blue: b, alpha: a)
+        } else {
+            // 如果不是合法的8位Hex,返回透明的颜色或其他默认值
+            return UIColor(white: 0.0, alpha: 0.0)
+        }
     }
 }
 
@@ -41,13 +44,13 @@ extension UIColor {
         var green: CGFloat = 0
         var blue: CGFloat = 0
         var alpha: CGFloat = 0
-
+        
         guard self.getRed(&red, green: &green, blue: &blue, alpha: &alpha) else {
             return nil
         }
-
+        
         let rgb: Int = (Int)(red * 255) << 16 | (Int)(green * 255) << 8 | (Int)(blue * 255) << 0
-
+        
         return String(format: "#%06x", rgb)
     }
 }

+ 7 - 0
ios/Classes/CompdfkitFlutterPlugin.swift

@@ -1,3 +1,10 @@
+//  Copyright © 2014-2025 PDF Technologies, Inc. All Rights Reserved.
+//
+//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+//  This notice may not be removed from this file.
+
 import Flutter
 import UIKit
 import ComPDFKit

+ 49 - 15
ios/Classes/reader/CPDFDocumentPlugin.swift

@@ -1,7 +1,7 @@
 //
 //  CPDFDocumentPlugin.swift
 //  compdfkit_flutter
-//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+//  Copyright © 2014-2025 PDF Technologies, Inc. All Rights Reserved.
 //
 //  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
 //  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
@@ -76,30 +76,64 @@ public class CPDFDocumentPlugin {
                 let initInfo = call.arguments as? [String: Any]
                 let path = initInfo?["filePath"] as? String ?? ""
                 let password = initInfo?["password"] ?? ""
-                //TODO: 修改这个打开文件方法, 根据打开文档的结果返回对应值, 要是没有对应的错误就不管
-                // result("success")
-                // 打开成功:"success"
-                // 打开失败,文档存在密码 : "errorPassword"
-                // 错误文件 : "errorFile"
-                // 错误页面 : "errorPage"
-                // 错误的格式 : "errorFormat"
-                // 未知 : "unknown"
-                // 错误安全性 : "errorSecurity"
-                // 未验证许可证 : "notVerifyLicense"
-                // 无读取权限 : "noReadPermission"
-                
+              
                 self.document = CPDFDocument(url: URL(fileURLWithPath: path))
                 if(self.document?.isLocked == true){
                     let success = self.document?.unlock(withPassword: password as? String ?? "")
                     if(success == true){
-                        result("success")
+                        if let error = self.document?.error as? NSError {
+                            let code = error.code
+                            
+                            switch code {
+                            case CPDFDocumentUnknownError:
+                                result("unknown")
+                            case CPDFDocumentFileError:
+                                result("errorFile")
+                            case CPDFDocumentFormatError:
+                                result("errorFormat")
+                            case CPDFDocumentPasswordError:
+                                result("errorPassword")
+                            case CPDFDocumentSecurityError:
+                                result("errorSecurity")
+                            case CPDFDocumentPageError:
+                                result("errorPage")
+                            default:
+                                result("success")
+                            }
+                        } else {
+                            result("success")
+                        }
+                        
                     }else {
                         result("errorPassword")
                     }
+                } else {
+                    if let error = self.document?.error as? NSError {
+                        let code = error.code
+                        
+                        switch code {
+                        case CPDFDocumentUnknownError:
+                            result("unknown")
+                        case CPDFDocumentFileError:
+                            result("errorFile")
+                        case CPDFDocumentFormatError:
+                            result("errorFormat")
+                        case CPDFDocumentPasswordError:
+                            result("errorPassword")
+                        case CPDFDocumentSecurityError:
+                            result("errorSecurity")
+                        case CPDFDocumentPageError:
+                            result("errorPage")
+                        default:
+                            result("success")
+                        }
+                    } else {
+                        result("success")
+                    }
                 }
                 self.pdfViewController?.pdfListView?.document = self.document
                 self.pdfViewController?.pdfListView?.setNeedsDisplay()
-                result(true)
+
             case CPDFConstants.getFileName:
                 if(self.document == nil){
                     print("self.document is nil")

+ 1 - 1
ios/Classes/reader/CPDFViewCtrlFactory.swift

@@ -1,7 +1,7 @@
 //
 //  CPDFViewCtrlFactory.swift
 //
-//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+//  Copyright © 2014-2025 PDF Technologies, Inc. All Rights Reserved.
 //
 //  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
 //  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.

+ 3 - 2
ios/Classes/reader/CPDFViewCtrlPlugin.swift

@@ -1,7 +1,7 @@
 //
 //  CPDFViewCtrlPlugin.swift
 //
-//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+//  Copyright © 2014-2025 PDF Technologies, Inc. All Rights Reserved.
 //
 //  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
 //  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
@@ -249,7 +249,8 @@ class CPDFViewCtrlPlugin {
             case CPDFConstants.showBotaView:
                 self.pdfViewController.buttonItemClicked_Bota(UIButton(frame: .zero))
             case CPDFConstants.showAddWatermarkView:
-                self.pdfViewController.enterPDFWatermark()
+                let isSaveAs = call.arguments as! Bool
+                self.pdfViewController.enterPDFWatermark(isSaveAs: isSaveAs)
             case CPDFConstants.showSecurityView:
                 self.pdfViewController.enterPDFSecurity()
             case CPDFConstants.showDisplaySettingsView: