1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- //
- // 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
- import Flutter
- 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 : Any];
- let filePath = (convertData[params_file_path] as? String) ?? "";
- let convertType = convertData[params_convert_type] as! String;
- let taskId = (convertData[params_task_id] as? String) ?? "";
- let fileName = (convertData[params_file_name] as? String ) ?? "";
- 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_task_id: taskId, "status" : status, "outputPath" : outputPath ?? ""] as [String : Any])
- }
-
- }
- return nil
- }
- public func onCancel(withArguments arguments: Any?) -> FlutterError? {
- return nil
- }
-
- }
|