123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- //
- // CPDFViewCtrlFactory.swift
- //
- // Copyright © 2014-2023 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 Flutter
- import UIKit
- import ComPDFKit
- import ComPDFKit_Tools
- class CPDFViewCtrlFactory: NSObject, FlutterPlatformViewFactory {
- private let messenger: FlutterBinaryMessenger
- init(messenger: FlutterBinaryMessenger) {
- self.messenger = messenger
- super.init()
- }
- func create(
- withFrame frame: CGRect,
- viewIdentifier viewId: Int64,
- arguments args: Any?
- ) -> FlutterPlatformView {
- return CPDFViewCtrlFlutter(
- frame: frame,
- viewIdentifier: viewId,
- arguments: args,
- binaryMessenger: messenger)
- }
-
- func createArgsCodec() -> FlutterMessageCodec & NSObjectProtocol {
- return FlutterStandardMessageCodec.sharedInstance()
- }
- }
- class CPDFViewCtrlFlutter: NSObject, FlutterPlatformView, CPDFViewBaseControllerDelete {
-
- private var pdfViewController : CPDFViewController
-
- private var navigationController : CNavigationController
- init(
- frame: CGRect,
- viewIdentifier viewId: Int64,
- arguments args: Any?,
- binaryMessenger messenger: FlutterBinaryMessenger?
- ) {
- // Parses the document path, password, and configuration information
- let initInfo = args as? [String: Any]
- let jsonString = initInfo?["configuration"] ?? ""
- let password = initInfo?["password"] ?? ""
- let path = initInfo?["document"] as? String ?? ""
-
- let document = NSURL(fileURLWithPath: path)
-
- let fileManager = FileManager.default
- let samplesFilePath = NSHomeDirectory().appending("/Documents/Files")
- 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 jsonDataParse = CPDFJSONDataParse(String: jsonString as! String)
- let configuration = jsonDataParse.configuration
-
- // Create the pdfview controller view
- pdfViewController = CPDFViewController(filePath: docsFilePath, password: password as? String, configuration: configuration!)
-
- navigationController = CNavigationController(rootViewController: pdfViewController)
- navigationController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
- navigationController.view.frame = frame
-
- var plugin = CPDFViewCtrlPlugin(viewId: viewId, binaryMessenger: messenger!, controller: pdfViewController)
- super.init()
-
- // Proxy set, but not used
- pdfViewController.delegate = self
-
- navigationController.setViewControllers([pdfViewController], animated: true)
- }
- func view() -> UIView {
- return navigationController.view
- }
-
- public func PDFViewBaseControllerDissmiss(_ baseControllerDelete: CPDFViewBaseController) {
- }
- }
|