|
@@ -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
|
|
|
|