123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- //
- // RCTCPDFViewManager.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
- @objc(RCTCPDFReaderView)
- class RCTCPDFReaderView: RCTViewManager, RCTCPDFViewDelegate {
-
- @objc override static func requiresMainQueueSetup() -> Bool {
- return true
- }
-
- var cpdfViews: Dictionary<Int, RCTCPDFView> = [:]
-
- @objc override func view() -> UIView! {
- let rtcCPDFView = RCTCPDFView()
- rtcCPDFView.delegate = self
- return rtcCPDFView
- }
-
- func saveDocument(forCPDFViewTag tag: Int, completionHandler: @escaping (Bool) -> Void) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.saveDocument(completionHandler: { success in
- completionHandler(success)
-
- if (success) {
- if let onChange = rtcCPDFView?.onChange {
- onChange(["saveDocument": "saveDocument"])
- }
- }
- })
- }
-
- func setMargins(forCPDFViewTag tag: Int, left : Int, top : Int, right : Int, bottom : Int) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.setMargins(left: left, top: top, right: right, bottom: bottom)
- }
-
- func removeAllAnnotations(forCPDFViewTag tag: Int, completionHandler: @escaping (Bool) -> Void) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.removeAllAnnotations(completionHandler: { success in
- completionHandler(success)
- })
- }
-
- func importAnnotations(forCPDFViewTag tag: Int, xfdfFile : URL, completionHandler: @escaping (Bool) -> Void) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.importAnnotations(xfdfFile: xfdfFile, completionHandler: { success in
- completionHandler(success)
- })
- }
-
- func exportAnnotations(forCPDFViewTag tag: Int, completionHandler: @escaping (String) -> Void) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.exportAnnotations(completionHandler: { success in
- completionHandler(success)
- })
- }
-
- func setDisplayPageIndex(forCPDFViewTag tag : Int, pageIndex : Int) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.setDisplayPageIndex(pageIndex: pageIndex)
- }
-
- func getCurrentPageIndex(forCPDFViewTag tag: Int, completionHandler: @escaping (Int) -> Void) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.getCurrentPageIndex(completionHandler: { pageIndex in
- completionHandler(pageIndex)
- })
- }
-
- func hasChange(forCPDFViewTag tag: Int, completionHandler: @escaping (Bool) -> Void) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.hasChange(completionHandler: { success in
- completionHandler(success)
- })
- }
-
- func setScale(forCPDFViewTag tag : Int, scale : NSNumber) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.setScale(scale: scale)
- }
-
- func getScale(forCPDFViewTag tag : Int, completionHandler: @escaping (NSNumber) -> Void) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.getScale(completionHandler: { success in
- completionHandler(success)
- })
- }
-
- func setReadBackgroundColor(forCPDFViewTag tag : Int, displayMode : NSString) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.setReadBackgroundColor(displayMode: displayMode)
- }
-
- func getReadBackgroundColor(forCPDFViewTag tag : Int, completionHandler: @escaping (NSString) -> Void){
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.getReadbackgroundColor(completionHandler: {color in
- completionHandler(color)
- })
- }
-
- func setFormFieldHighlight(forCPDFViewTag tag : Int, formFieldHighlight : Bool) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.setFormFieldHighlight(formFieldHighlight: formFieldHighlight)
- }
-
- func isFormFieldHighlight(forCPDFViewTag tag : Int, completionHandler: @escaping (Bool) -> Void){
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.isFormFieldHighlight(completionHandler: {highlight in
- completionHandler(highlight)
- })
- }
-
- func setLinkHighlight(forCPDFViewTag tag : Int, linkHighlight : Bool) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.setLinkHighlight(linkHighlight: linkHighlight)
- }
-
- func isLinkHighlight(forCPDFViewTag tag : Int, completionHandler: @escaping (Bool) -> Void){
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.isLinkHighlight(completionHandler: {highlight in
- completionHandler(highlight)
- })
- }
-
- func setVerticalMode(forCPDFViewTag tag : Int, isVerticalMode : Bool) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.setVerticalMode(isVerticalMode: isVerticalMode)
- }
-
- func isVerticalMode(forCPDFViewTag tag : Int, completionHandler: @escaping (Bool) -> Void){
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.isVerticalMode(completionHandler: {isVertical in
- completionHandler(isVertical)
- })
- }
-
- func setContinueMode(forCPDFViewTag tag : Int, isContinueMode : Bool) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.setContinueMode(isContinueMode: isContinueMode)
- }
-
- func isContinueMode(forCPDFViewTag tag : Int, completionHandler: @escaping (Bool) -> Void){
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.isContinueMode(completionHandler: {isContinue in
- completionHandler(isContinue)
- })
- }
-
- func setDoublePageMode(forCPDFViewTag tag : Int, isDoublePageMode : Bool) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.setDoublePageMode(isDoublePageMode: isDoublePageMode)
- }
-
- func isDoublePageMode(forCPDFViewTag tag : Int, completionHandler: @escaping (Bool) -> Void){
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.isDoublePageMode(completionHandler: {isDoublePage in
- completionHandler(isDoublePage)
- })
- }
-
- func setCoverPageMode(forCPDFViewTag tag : Int, isCoverPageMode : Bool) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.setCoverPageMode(isCoverPageMode: isCoverPageMode)
- }
-
- func isCoverPageMode(forCPDFViewTag tag : Int, completionHandler: @escaping (Bool) -> Void){
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.isCoverPageMode(completionHandler: { isCoverPageMode in
- completionHandler(isCoverPageMode)
- })
- }
-
- func setCropMode(forCPDFViewTag tag : Int, isCropMode : Bool) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.setCropMode(isCropMode: isCropMode)
- }
-
- func isCropMode(forCPDFViewTag tag : Int, completionHandler: @escaping (Bool) -> Void){
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.isCropMode(completionHandler: completionHandler)
- }
-
- func getFileName(forCPDFViewTag tag : Int, completionHandler: @escaping (String) -> Void){
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.getFileName(completionHandler: completionHandler)
- }
-
- func isEncrypted(forCPDFViewTag tag : Int, completionHandler: @escaping (Bool) -> Void){
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.isEncrypted(completionHandler: completionHandler)
- }
-
- func isImageDoc(forCPDFViewTag tag : Int, completionHandler: @escaping (Bool) -> Void){
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.isImageDoc(completionHandler: completionHandler)
- }
-
- func getPermissions(forCPDFViewTag tag : Int, completionHandler: @escaping (NSNumber) -> Void) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.getPermissions(completionHandler: completionHandler)
- }
-
- func getPageCount(forCPDFViewTag tag : Int, completionHandler: @escaping (NSNumber) -> Void) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.getPageCount(completionHandler: completionHandler)
- }
-
- func checkOwnerUnlocked(forCPDFViewTag tag : Int, completionHandler: @escaping (Bool) -> Void) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.checkOwnerUnlocked(completionHandler: completionHandler)
- }
-
- func checkOwnerPassword(forCPDFViewTag tag : Int, password : String, completionHandler: @escaping (Bool) -> Void) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.checkOwnerPassword(password: password, completionHandler: completionHandler)
- }
-
- func getEncryptAlgo(forCPDFViewTag tag : Int, completionHandler: @escaping (String) -> Void) {
- let rtcCPDFView = cpdfViews[tag]
- rtcCPDFView?.getEncryptAlgo(completionHandler: completionHandler)
- }
-
- // MARK: - RCTCPDFViewDelegate
-
- func cpdfViewAttached(_ cpdfView: RCTCPDFView) {
- cpdfViews[cpdfView.reactTag.intValue] = cpdfView
- }
-
- func saveDocumentChange(_ cpdfView: RCTCPDFView) {
- if let onChange = cpdfView.onChange {
- onChange(["saveDocument": "saveDocument"])
- }
- }
-
- func onPageChanged(_ cpdfView: RCTCPDFView, pageIndex: Int) {
- if let onChange = cpdfView.onChange {
- onChange(["onPageChanged": pageIndex])
- }
- }
-
- }
|