// // ConverFilePlugin.swift // Runner // // 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 Foundation import ComPDFKit_Conversion class ConverFilePlugin{ init(messenger : FlutterBinaryMessenger){ let channel = FlutterEventChannel(name: "com.compdfkit.conversion.flutter.convert", binaryMessenger: messenger) channel.setStreamHandler(SwiftStreamHandler()) } } class SwiftStreamHandler: NSObject,FlutterStreamHandler { var util:ConvertUtil? public func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? { let convertData = arguments as! [String: String]; let filePath = convertData[params_file_path] ?? ""; let convertType = convertData[params_convert_type]!; let dataTag = String(convertData[params_data_tag]!); let fileName = convertData[params_file_name] ?? ""; let queue = DispatchQueue(label: "com.compdfkit.conversion.flutter") queue.async { self.util = ConvertUtil() let options = self.util?.getConvertOptions(withArguments: arguments) self.util?.convert(options: options!, filePath: filePath,fileName: fileName, convertType: convertType) { progress, status, outputPath in events(["progress": progress, params_data_tag: dataTag, "status" : status, "outputPath" : outputPath]) } } return nil } public func onCancel(withArguments arguments: Any?) -> FlutterError? { return nil } }