|
@@ -12,10 +12,17 @@
|
|
|
|
|
|
import UIKit
|
|
|
import ComPDFKit_Tools
|
|
|
+import ComPDFKit
|
|
|
+
|
|
|
+protocol RCTCPDFViewDelegate: AnyObject {
|
|
|
+ func cpdfViewAttached(_ cpdfView: RCTCPDFView)
|
|
|
+}
|
|
|
|
|
|
class RCTCPDFView: UIView {
|
|
|
|
|
|
- private var pdfViewController : CPDFViewController?
|
|
|
+ weak var delegate: RCTCPDFViewDelegate?
|
|
|
+
|
|
|
+ public var pdfViewController : CPDFViewController?
|
|
|
|
|
|
private var navigationController : CNavigationController?
|
|
|
|
|
@@ -27,11 +34,24 @@ class RCTCPDFView: UIView {
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
}
|
|
|
|
|
|
+ // MARK: - Private Methods
|
|
|
+
|
|
|
private func createCPDFView() {
|
|
|
+ let fileManager = FileManager.default
|
|
|
+ let samplesFilePath = NSHomeDirectory().appending("/Documents/ReaderViewer")
|
|
|
+ let fileName = document.lastPathComponent
|
|
|
+ let docsFilePath = samplesFilePath + "/" + fileName
|
|
|
+
|
|
|
+ if !fileManager.fileExists(atPath: samplesFilePath) {
|
|
|
+ try? FileManager.default.createDirectory(atPath: samplesFilePath, withIntermediateDirectories: true, attributes: nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ try? FileManager.default.copyItem(atPath: document.path, toPath: docsFilePath)
|
|
|
+
|
|
|
let jsonData = CPDFJSONDataParse(String: configuration)
|
|
|
let configurations = jsonData.configuration ?? CPDFConfiguration()
|
|
|
|
|
|
- pdfViewController = CPDFViewController(filePath: document.path, password: password, configuration: configurations)
|
|
|
+ pdfViewController = CPDFViewController(filePath: docsFilePath, password: password, configuration: configurations)
|
|
|
navigationController = CNavigationController(rootViewController: pdfViewController!)
|
|
|
navigationController?.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
|
navigationController?.view.frame = self.frame
|
|
@@ -39,8 +59,20 @@ class RCTCPDFView: UIView {
|
|
|
navigationController?.setViewControllers([pdfViewController!], animated: true)
|
|
|
|
|
|
addSubview(navigationController?.view ?? UIView())
|
|
|
+
|
|
|
+ self.delegate?.cpdfViewAttached(self)
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: - Public Methods
|
|
|
+
|
|
|
+ func saveDocument(completionHandler: @escaping (Bool) -> Void) {
|
|
|
+ let document = self.pdfViewController?.pdfListView?.document
|
|
|
+ let success = document?.write(to: document?.documentURL ?? URL(fileURLWithPath: ""), isSaveFontSubset: true) ?? false
|
|
|
+ completionHandler(success)
|
|
|
}
|
|
|
|
|
|
+ // MARK: - RCT Methods
|
|
|
+
|
|
|
private var configuration: String = ""
|
|
|
@objc func setConfiguration(_ newSection: String) {
|
|
|
configuration = newSection
|