Browse Source

ComPDFKit(RN) - 2.2.1 iOS 新增相关接口接入

yangliuhua 1 month ago
parent
commit
20e21ee1fb

+ 2 - 2
example/ios/Podfile

@@ -16,8 +16,8 @@ end
 
 target 'CompdfkitPdfExample' do
   config = use_native_modules!
-  pod "ComPDFKit", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.2.0.podspec'
-  pod "ComPDFKit_Tools", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/2.2.0.podspec'
+  pod "ComPDFKit", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.2.1.podspec'
+  pod "ComPDFKit_Tools", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/2.2.1.podspec'
 
 
   use_react_native!(

+ 21 - 2
example/ios/en.lproj/Localizable.strings

@@ -5,7 +5,7 @@
   Localizable.strings
   PDFViewer
 
- //  Copyright © 2014-2024 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.
@@ -36,7 +36,8 @@
 "Technical Support" = "Technical Support";
 "support@compdf.com" = "support@compdf.com";
 "Technical Supports" = "Technical Support";
-"© 2014-2024 PDF Technologies, Inc. All Rights Reserved." = "© 2014-2024 PDF Technologies, Inc. All Rights Reserved.";
+"Mail account is not set up!" = "Mail account is not set up!";
+"© 2014-2025 PDF Technologies, Inc. All Rights Reserved." = "© 2014-2025 PDF Technologies, Inc. All Rights Reserved.";
 "Privacy Policy" = "Privacy Policy";
 "Service Terms" = "Service Terms";
 "Click to Open & Process" = "Click to Open & Process";
@@ -49,6 +50,7 @@
 "Save as Flattened PDF" = "Save as Flattened PDF";
 "_Flattened" = "_Flattened";
 "Sorry PDF Reader Can't open this pdf file!" = "Sorry PDF Reader Can't open this pdf file!";
+"The current page is scanned images that do not support adding highlights, underlines, strikeouts, and squiggly lines." = "The current page is scanned images that do not support adding highlights, underlines, strikeouts, and squiggly lines.";
 
 "Sorry PDF Reader Can't open this pdf file!" = "Sorry PDF Reader Can't open this pdf file!";
 "Your consent is required before you could access the function." = "Your consent is required before you could access the function.";
@@ -114,6 +116,7 @@
 "Ignore Case" = "Ignore Case";
 "Whole Words only" = "Whole Words only";
 "Effective immediately after setting" = "Effective immediately after setting";
+"Please enter the password" = "Please enter the password";
 
 "View Setting" = "View Setting";
 "Document Info" = "Document Info";
@@ -129,6 +132,7 @@
 "Split View" = "Split View";
 "Vertical Scrolling" = "Vertical";
 "Horizontal Scrolling" = "Horizontal";
+"Vertical Scrolling Paging" = "Page Break";
 "Themes" = "Themes";
 "Light" = "Light";
 "Dark" = "Dark";
@@ -231,6 +235,7 @@
 "Stroke Color" = "Stroke Color";
 "Fill Color" = "Fill Color";
 "Line and Border Style" = "Line and Border Style";
+"Dash Spacing" = "Dash Spacing";
 "Start" = "Start";
 "End" = "End";
 "Arrow Style" = "Arrow Style";
@@ -289,6 +294,7 @@
 "Paste and Match Style" = "Paste and Match Style";
 "Crop" = "Crop";
 "Export Successfully!" = "Export Successfully!";
+"Styles" = "Style";
 "Select All" = "Select All";
 
 "Text Field" = "Text Field";
@@ -548,3 +554,16 @@
 "Marked" = "Marked";
 "Reply" = "Reply";
 "View Reply" = "View Reply";
+
+"Compress" = "Compress";
+"Selected File" = "Selected File";
+"Change" = "Change";
+"Compress Quality" = "Compress Quality";
+"Low Quality" = "Low Quality";
+"Standard Quality" = "Standard Quality";
+"High Quality" = "High Quality";
+"Custom" = "Custom";
+"Saving Path" = "Saving Path";
+"Compressing" = "Compressing";
+"Incorrect password, please try again." = "Incorrect password, please try again.";
+"Compressed successfully!" = "Compressed successfully!";

+ 21 - 2
example/ios/zh-Hans.lproj/Localizable.strings

@@ -2,7 +2,7 @@
   Localizable.strings
   PDFViewer
 
- //  Copyright © 2014-2024 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.
@@ -33,7 +33,8 @@
 "Technical Support" = "技术支持";
 "support@compdf.com" = "support@compdf.com";
 "Technical Supports" = "ComPDFKit技术支持请求";
-"© 2014-2024 PDF Technologies, Inc. All Rights Reserved." = "© 2014-2024 PDF Technologies, Inc. All Rights Reserved.";
+"Mail account is not set up!" = "尚未设置Email邮箱";
+"© 2014-2025 PDF Technologies, Inc. All Rights Reserved." = "© 2014-2025 PDF Technologies, Inc. All Rights Reserved.";
 "Privacy Policy" = "隐私协议";
 "Service Terms" = "服务条款";
 "Click to Open & Process" = "点击打开 & 处理文档";
@@ -46,6 +47,7 @@
 "Save as Flattened PDF" = "另存为扁平化副本";
 "_Flattened" = "_扁平化文档";
 "Sorry PDF Reader Can't open this pdf file!" = "对不起,PDF阅读器无法打开此PDF文件!";
+"The current page is scanned images that do not support adding highlights, underlines, strikeouts, and squiggly lines." = "当前页面为图像。不支持添加高光、下划线、删除线和波浪线等注释。";
 
 "Your consent is required before you could access the function." = "在您访问该功能之前需要您的同意。";
 
@@ -96,6 +98,7 @@
 "This PDF has password protect." = "这个PDF有密码保护。";
 "Please input the password below:" = "请在下方输入密码:";
 "The password is invalid !" = "密码无效!";
+"Please enter the password" = "请输入文档密码";
 
 "Viewer" = "查看器";
 "Annotations" = "注释";
@@ -127,6 +130,7 @@
 "Split View" = "分屏视图";
 "Vertical Scrolling" = "垂直";
 "Horizontal Scrolling" = "水平";
+"Vertical Scrolling Paging" = "分页";
 "Themes" = "主题";
 "Light" = "日间模式";
 "Dark" = "夜间模式";
@@ -228,6 +232,7 @@
 "Stroke Color" = "边框颜色";
 "Fill Color" = "填充颜色";
 "Line and Border Style" = "线型";
+"Dash Spacing" = "虚线";
 "Start" = "线头";
 "End" = "线尾";
 "Arrow Style" = "箭头样式";
@@ -288,6 +293,7 @@
 "Paste and Match Style" = "带样式粘贴";
 "Export Successfully!" = "图片导出成功!";
 "Exit" = "退出";
+"Styles" = "效果";
 "Select All" = "选择全部";
 
 "Text Field" = "文本域";
@@ -546,3 +552,16 @@
 "Marked" = "已标记";
 "Reply" = "回复";
 "View Reply" = "查看回复";
+
+"Compress" = "压缩";
+"Selected File" = "选中文档";
+"Change" = "更换";
+"Compress Quality" = "压缩质量";
+"Low Quality" = "低";
+"Standard Quality" = "标准";
+"High Quality" = "高";
+"Custom" = "自定义";
+"Saving Path" = "文件存储路径";
+"Compressing" = "正在压缩···";
+"Incorrect password, please try again." = "密码错误,请重试。";
+"Compressed successfully!" = "压缩成功";

+ 148 - 4
ios/RCTCPDFView.swift

@@ -346,6 +346,87 @@ class RCTCPDFView: UIView, CPDFViewBaseControllerDelete {
             completionHandler(true)
         }
     }
+    
+    func setPreviewMode(viewMode : String) {
+        switch viewMode {
+        case "viewer":
+            self.pdfViewController?.enterViewerMode()
+        case "annotations":
+            self.pdfViewController?.enterAnnotationMode()
+        case "contentEditor":
+            self.pdfViewController?.enterEditMode()
+        case "forms":
+            self.pdfViewController?.enterFormMode()
+        case "signatures":
+            self.pdfViewController?.enterSignatureMode()
+            default:
+            self.pdfViewController?.enterViewerMode()
+        }
+    }
+    
+    func getPreviewMode(completionHandler: @escaping (String) -> Void) {
+        let state = self.pdfViewController?.functionTypeState ?? .viewer
+        switch state {
+        case .viewer:
+            completionHandler("viewer")
+        case .edit:
+            completionHandler("contentEditor")
+        case .annotation:
+            completionHandler("annotations")
+        case .form:
+            completionHandler("forms")
+        case .signature:
+            completionHandler("signatures")
+        default:
+            completionHandler("viewer")
+        }
+    }
+    
+    func showThumbnailView(isEditMode : Bool) {
+        if isEditMode {
+            self.pdfViewController?.enterPDFPageEdit()
+        } else {
+            self.pdfViewController?.enterThumbnail()
+        }
+    }
+    
+    func showBotaView() {
+        self.pdfViewController?.buttonItemClicked_Bota(UIButton(frame: .zero))
+    }
+    
+    func showAddWatermarkView() {
+        self.pdfViewController?.enterPDFWatermark()
+    }
+    
+    func showSecurityView() {
+        self.pdfViewController?.enterPDFSecurity()
+    }
+    
+    func showDisplaySettingView() {
+        self.pdfViewController?.enterPDFSetting()
+    }
+    
+    func enterSnipMode() {
+        self.pdfViewController?.enterPDFSnipImageMode()
+    }
+    
+    func exitSnipMode() {
+        self.pdfViewController?.exitPDFSnipImageMode()
+    }
+    
+    func open(document : URL, password : String, completionHandler: @escaping (Bool) -> Void) {
+        if let pdfListView = self.pdfViewController?.pdfListView {
+            let newDocument = CPDFDocument(url: document)
+            if(newDocument?.isLocked == true){
+                newDocument?.unlock(withPassword: password)
+            }
+            pdfListView.document = newDocument
+            pdfListView.setNeedsDisplay()
+            completionHandler(true)
+        } else {
+            completionHandler(false)
+        }
+    }
 
     func getFileName(completionHandler: @escaping (String) -> Void){
         if let pdfListView = self.pdfViewController?.pdfListView {
@@ -412,6 +493,66 @@ class RCTCPDFView: UIView, CPDFViewBaseControllerDelete {
             completionHandler(false)
         }
     }
+    
+    func removePassword(completionHandler: @escaping (Bool) -> Void) {
+        if let pdfListView = self.pdfViewController?.pdfListView {
+            let newDocument = pdfListView.document
+            let url = newDocument?.documentURL
+            
+            let success = newDocument?.writeDecrypt(to: url, isSaveFontSubset: true) ?? false
+            completionHandler(success)
+        } else {
+            completionHandler(false)
+        }
+    }
+    
+    func setPassword(info : NSDictionary, completionHandler: @escaping (Bool) -> Void) {
+        if let pdfListView = self.pdfViewController?.pdfListView {
+            
+            let _info = info as? [String: Any]
+            
+            let userPassword : String = self.getValue(from: _info, key: "user_password", defaultValue: "")
+            let ownerPassword : String = self.getValue(from: _info, key: "owner_password", defaultValue: "")
+            let allowsPrinting : Bool = self.getValue(from: _info, key: "allows_printing", defaultValue: true)
+            let allowsCopying : Bool = self.getValue(from: _info, key: "allows_copying", defaultValue: true)
+            
+            let encryptAlgo : String = self.getValue(from: _info, key: "encrypt_algo", defaultValue: "rc4")
+            
+            var level: Int = 0
+            // Encryption mode, the type passed in is:rc4, aes128, aes256, noEncryptAlgo
+            switch encryptAlgo {
+            case "rc4":
+                level = 0
+            case "aes128":
+                level = 1
+            case "aes256":
+                level = 2
+            case "noEncryptAlgo":
+                level = 3
+            default:
+                level = 3
+            }
+            
+            var options:[CPDFDocumentWriteOption: Any] = [:]
+            options[CPDFDocumentWriteOption.userPasswordOption] = userPassword
+            
+            options[CPDFDocumentWriteOption.ownerPasswordOption] = ownerPassword
+            
+            options[CPDFDocumentWriteOption.allowsPrintingOption] = allowsPrinting
+            
+            options[CPDFDocumentWriteOption.allowsCopyingOption] = allowsCopying
+            
+            options[CPDFDocumentWriteOption.encryptionLevelOption] = NSNumber(value: level)
+            
+            let newDocument = pdfListView.document
+            let url = newDocument?.documentURL
+            
+            let success = newDocument?.write(to: url, withOptions: options, isSaveFontSubset: true) ?? false
+            completionHandler(success)
+        } else {
+            completionHandler(false)
+        }
+    }
 
     func getEncryptAlgo(completionHandler: @escaping (String) -> Void) {
         if let pdfListView = self.pdfViewController?.pdfListView {
@@ -432,10 +573,13 @@ class RCTCPDFView: UIView, CPDFViewBaseControllerDelete {
             completionHandler("noEncryptAlgo")
         }
     }
-
-
-
-
+    
+    func getValue<T>(from info: [String: Any]?, key: String, defaultValue: T) -> T {
+        guard let value = info?[key] as? T else {
+            return defaultValue
+        }
+        return value
+    }
 
     // MARK: - CPDFViewBaseControllerDelete
 

+ 65 - 0
ios/RCTCPDFViewManager.swift

@@ -191,6 +191,57 @@ class RCTCPDFReaderView: RCTViewManager, RCTCPDFViewDelegate {
         let rtcCPDFView = cpdfViews[tag]
         rtcCPDFView?.isCropMode(completionHandler: completionHandler)
     }
+    
+    func setPreviewMode(forCPDFViewTag tag : Int, viewMode : String) {
+        let rtcCPDFView = cpdfViews[tag]
+        rtcCPDFView?.setPreviewMode(viewMode: viewMode)
+    }
+    
+    func getPreviewMode(forCPDFViewTag tag : Int, completionHandler: @escaping (String) -> Void) {
+        let rtcCPDFView = cpdfViews[tag]
+        rtcCPDFView?.getPreviewMode(completionHandler: { mode in
+            completionHandler(mode)
+        })
+    }
+    
+    func showThumbnailView(forCPDFViewTag tag : Int, isEditMode : Bool) {
+        let rtcCPDFView = cpdfViews[tag]
+        rtcCPDFView?.showThumbnailView(isEditMode: isEditMode)
+    }
+    
+    func showBotaView(forCPDFViewTag tag : Int) {
+        let rtcCPDFView = cpdfViews[tag]
+        rtcCPDFView?.showBotaView()
+    }
+    
+    func showAddWatermarkView(forCPDFViewTag tag : Int) {
+        let rtcCPDFView = cpdfViews[tag]
+        rtcCPDFView?.showAddWatermarkView()
+    }
+    
+    func showSecurityView(forCPDFViewTag tag : Int) {
+        let rtcCPDFView = cpdfViews[tag]
+        rtcCPDFView?.showSecurityView()
+    }
+    
+    func showDisplaySettingView(forCPDFViewTag tag : Int) {
+        let rtcCPDFView = cpdfViews[tag]
+        rtcCPDFView?.showDisplaySettingView()
+    }
+    
+    func enterSnipMode(forCPDFViewTag tag : Int) {
+        let rtcCPDFView = cpdfViews[tag]
+        rtcCPDFView?.enterSnipMode()
+    }
+    
+    func exitSnipMode(forCPDFViewTag tag : Int) {
+        let rtcCPDFView = cpdfViews[tag]
+        rtcCPDFView?.exitSnipMode()
+    }
+    
+    func open(forCPDFViewTag : Int, document : URL, password : String, completionHandler: @escaping (Bool) -> Void) {
+        let rtcCPDFView = cpdfViews[forCPDFViewTag]
+    }
 
     func getFileName(forCPDFViewTag tag : Int, completionHandler: @escaping (String) -> Void){
         let rtcCPDFView = cpdfViews[tag]
@@ -226,6 +277,20 @@ class RCTCPDFReaderView: RCTViewManager, RCTCPDFViewDelegate {
         let rtcCPDFView = cpdfViews[tag]
         rtcCPDFView?.checkOwnerPassword(password: password, completionHandler: completionHandler)
     }
+    
+    func removePassword(forCPDFViewTag tag : Int, completionHandler: @escaping (Bool) -> Void) {
+        let rtcCPDFView = cpdfViews[tag]
+        rtcCPDFView?.removePassword(completionHandler: { success in
+            completionHandler(success)
+        })
+    }
+    
+    func setPassword(forCPDFViewTag tag : Int, info : NSDictionary, completionHandler: @escaping (Bool) -> Void) {
+        let rtcCPDFView = cpdfViews[tag]
+        rtcCPDFView?.setPassword(info: info, completionHandler: { success in
+            completionHandler(success)
+        })
+    }
 
     func getEncryptAlgo(forCPDFViewTag tag : Int, completionHandler: @escaping (String) -> Void) {
         let rtcCPDFView = cpdfViews[tag]

+ 104 - 0
ios/RCTDocumentManager.swift

@@ -278,6 +278,90 @@ class RCTDocumentManager: NSObject, RCTBridgeModule {
             })
         }
     }
+    
+    @objc(setPreviewMode: withViewMode:)
+    func setPreviewMode(forCPDFViewTag tag : Int, viewMode : String) {
+        DispatchQueue.main.async {
+            let reader = self.readerView()
+            reader.setPreviewMode(forCPDFViewTag: tag, viewMode: viewMode)
+        }
+    }
+    
+    @objc(getPreviewMode: withResolver: withRejecter:)
+    func getPreviewMode(forCPDFViewTag tag : Int, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock){
+        DispatchQueue.main.async {
+            let reader = self.readerView()
+            reader.getPreviewMode(forCPDFViewTag: tag) { mode in
+                resolve(mode)
+            }
+        }
+    }
+    
+    @objc(showThumbnailView: withEditMode:)
+    func showThumbnailView(forCPDFViewTag tag : Int, isEditMode : Bool) {
+        DispatchQueue.main.async {
+            let reader = self.readerView()
+            reader.showThumbnailView(forCPDFViewTag: tag, isEditMode: isEditMode)
+        }
+    }
+    
+    @objc(showBotaView:)
+    func showBotaView(forCPDFViewTag tag : Int) {
+        DispatchQueue.main.async {
+            let reader = self.readerView()
+            reader.showBotaView(forCPDFViewTag: tag)
+        }
+    }
+    
+    @objc(showAddWatermarkView:)
+    func showAddWatermarkView(forCPDFViewTag tag : Int) {
+        DispatchQueue.main.async {
+            let reader = self.readerView()
+            reader.showAddWatermarkView(forCPDFViewTag: tag)
+        }
+    }
+    
+    @objc(showSecurityView:)
+    func showSecurityView(forCPDFViewTag tag : Int) {
+        DispatchQueue.main.async {
+            let reader = self.readerView()
+            reader.showSecurityView(forCPDFViewTag: tag)
+        }
+    }
+    
+    @objc(showDisplaySettingView:)
+    func showDisplaySettingView(forCPDFViewTag tag : Int) {
+        DispatchQueue.main.async {
+            let reader = self.readerView()
+            reader.showDisplaySettingView(forCPDFViewTag: tag)
+        }
+    }
+    
+    @objc(enterSnipMode:)
+    func enterSnipMode(forCPDFViewTag tag : Int) {
+        DispatchQueue.main.async {
+            let reader = self.readerView()
+            reader.enterSnipMode(forCPDFViewTag: tag)
+        }
+    }
+    
+    @objc(exitSnipMode:)
+    func exitSnipMode(forCPDFViewTag tag : Int) {
+        DispatchQueue.main.async {
+            let reader = self.readerView()
+            reader.exitSnipMode(forCPDFViewTag: tag)
+        }
+    }
+    
+    @objc(open: withDocument: withPassword: withResolver: withRejecter:)
+    func open(forCPDFViewTag tag: Int, document : URL, password : String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock){
+        DispatchQueue.main.async {
+            let reader = self.readerView()
+            reader.open(forCPDFViewTag: tag, document: document, password: password) { success in
+                resolve(success)
+            }
+        }
+    }
 
     @objc(getFileName: withResolver: withRejecter:)
     func getFileName(forCPDFViewTag tag : Int, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock){
@@ -349,6 +433,26 @@ class RCTDocumentManager: NSObject, RCTBridgeModule {
             })
         }
     }
+    
+    @objc(removePassword: withResolver: withRejecter:)
+    func removePassword(forCPDFViewTag tag : Int, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock){
+        DispatchQueue.main.async {
+            let reader = self.readerView()
+            reader.removePassword(forCPDFViewTag: tag) { success in
+                resolve(success)
+            }
+        }
+    }
+    
+    @objc(setPassword: withInfo: withResolver: withRejecter:)
+    func setPassword(forCPDFViewTag tag : Int, info : NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock){
+        DispatchQueue.main.async {
+            let reader = self.readerView()
+            reader.setPassword(forCPDFViewTag: tag, info: info) { success in
+                resolve(success)
+            }
+        }
+    }
 
     @objc(getEncryptAlgo: withResolver: withRejecter:)
     func getEncryptAlgo(forCPDFViewTag tag : Int, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {