// // RCTCPDFView.swift // react-native-compdfkit-pdf // // Copyright © 2014-2024 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 import ComPDFKit_Tools class RCTCPDFView: UIView { private var pdfViewController : CPDFViewController? private var navigationController : CNavigationController? init() { super.init(frame: CGRect(x: 0, y: 0, width: 500, height: 400)) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } private func createCPDFView() { let jsonData = CPDFJSONDataParse(String: configuration) let configurations = jsonData.configuration ?? CPDFConfiguration() pdfViewController = CPDFViewController(filePath: document.path, password: password, configuration: configurations) navigationController = CNavigationController(rootViewController: pdfViewController!) navigationController?.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] navigationController?.view.frame = self.frame navigationController?.setViewControllers([pdfViewController!], animated: true) addSubview(navigationController?.view ?? UIView()) } private var configuration: String = "" @objc func setConfiguration(_ newSection: String) { configuration = newSection if (document.path.count > 1) && (configuration.count > 1) { createCPDFView() } } private var document: URL = URL(fileURLWithPath: "") @objc func setDocument(_ newSection: URL) { document = newSection if (document.path.count > 1) && (configuration.count > 1) { createCPDFView() } } private var password: String = "" @objc func setPassword(_ newSection: String) { password = newSection } }