RCTDocumentManager.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // RCTDocumentManager.swift
  3. // react-native-compdfkit-pdf
  4. //
  5. // Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. import UIKit
  13. import ComPDFKit
  14. @objc(CPDFViewManager)
  15. class RCTDocumentManager: NSObject, RCTBridgeModule {
  16. static func moduleName() -> String! {
  17. return "RCTDocumentManager"
  18. }
  19. internal var bridge: RCTBridge!
  20. @objc func readerView() -> RCTCPDFReaderView {
  21. self.bridge.module(for: RCTCPDFReaderView.self) as! RCTCPDFReaderView
  22. }
  23. @objc(save: withResolver: withRejecter:)
  24. func save(tag: Int, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
  25. DispatchQueue.main.async {
  26. let reader = self.readerView()
  27. reader.saveDocument(forCPDFViewTag: tag) { success in
  28. if success {
  29. resolve(success)
  30. } else {
  31. reject("save_failed", "Failed to save document", nil);
  32. }
  33. }
  34. }
  35. }
  36. }