123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- //
- // 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
- }
- }
|