compdfkit.dart 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  2. ///
  3. /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  4. /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  5. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  6. /// This notice may not be removed from this file.
  7. import 'dart:io';
  8. import 'package:compdfkit_flutter/cpdf_configuration.dart';
  9. import 'package:flutter/services.dart';
  10. class ComPDFKit {
  11. static const MethodChannel _methodChannel =
  12. MethodChannel('com.compdfkit.flutter.plugin');
  13. static const initSDK = 'init_sdk';
  14. static const sdkVersionCode = 'sdk_version_code';
  15. static const sdkBuildTag = "sdk_build_tag";
  16. /// init ComPDFKit sdk, please enter your ComPDFKit [key] and [secret]
  17. /// A new license is enabled in ComPDFKit SDK V1.11.0.
  18. /// If you are using a version before V1.11.0 and do not have a new license,
  19. /// please contact our technical team.
  20. static void init(String key) async {
  21. _methodChannel.invokeMethod(initSDK, {'key': key});
  22. }
  23. /// get ComPDFKit SDK version code
  24. static Future<String> getVersionCode() async {
  25. String versionCode =
  26. await _methodChannel.invokeMethod(ComPDFKit.sdkVersionCode);
  27. return versionCode;
  28. }
  29. /// get ComPDFKit SDK build tag info
  30. static Future<String> getSDKBuildTag() async {
  31. String buildTag = await _methodChannel.invokeMethod(ComPDFKit.sdkBuildTag);
  32. return buildTag;
  33. }
  34. /// Pass in the local file path of the PDF document and display it within a newly opened view.
  35. static void openDocument(String document,
  36. {String? password, CPDFConfiguration? configuration}) async {
  37. await _methodChannel.invokeMethod('openDocument', <String, dynamic>{
  38. 'document': document,
  39. 'password': password,
  40. 'configuration': configuration?.toJson()
  41. });
  42. }
  43. /// Retrieve the temporary directory path of the currently running platform.
  44. /// Currently, only [Android] and [IOS] are supported.
  45. static Future<Directory> getTemporaryDirectory() async {
  46. final String? path =
  47. await _methodChannel.invokeMethod('getTemporaryDirectory');
  48. if (path == null) {
  49. throw Exception('Unable to get temporary directory');
  50. }
  51. return Directory(path);
  52. }
  53. }