compdfkit.dart 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ///
  2. /// Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
  3. ///
  4. /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  5. /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  6. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  7. /// This notice may not be removed from this file.
  8. ///
  9. import 'dart:io';
  10. import 'package:compdfkit_flutter/cpdf_configuration.dart';
  11. import 'package:flutter/services.dart';
  12. /// ComPDFKit plugin to load PDF and image documents on both platform iOS and Android.
  13. class ComPDFKit {
  14. static const MethodChannel _methodChannel =
  15. MethodChannel('com.compdfkit.flutter.plugin');
  16. static const initSDK = 'init_sdk';
  17. static const initSdkKeys = 'init_sdk_keys';
  18. static const sdkVersionCode = 'sdk_version_code';
  19. static const sdkBuildTag = "sdk_build_tag";
  20. /// Please enter your ComPDFKit license to initialize the ComPDFKit SDK.<br/>
  21. /// This method is used for offline license authentication.
  22. /// In version **1.13.0**, we have introduced a brand-new online authentication licensing scheme.
  23. /// By default, the ComPDFKit SDK performs online authentication.
  24. /// If you are unsure about the type of your license, please contact the [ComPDFKit team.](https://www.compdf.com/support).
  25. ///
  26. /// **samples:**<br/>
  27. /// ```dart
  28. /// ComPDFKit.init('your compdfkit license')
  29. /// ```
  30. static void init(String key) async {
  31. _methodChannel.invokeMethod(initSDK, {'key': key});
  32. }
  33. /// Please enter your ComPDFKit license to initialize the ComPDFKit SDK.<br/>
  34. /// This method is used for online license authentication
  35. /// In version **1.13.0**, we have introduced a brand-new online authentication licensing scheme.
  36. /// By default, the ComPDFKit SDK performs online authentication.
  37. /// If you obtained your ComPDFKit License before the release of version 1.13.0, please use [ComPDFKit.init] <br/>
  38. /// If you are unsure about the type of your license, please contact the [ComPDFKit team.](https://www.compdf.com/support).
  39. ///
  40. /// **samples:**<br/>
  41. /// **online auth**
  42. /// ```dart
  43. /// ComPDFKit.initialize(androidOnlineLicense : 'your android platform compdfkit license', iosOnlineLicense: 'your ios platform compdfkit license')
  44. /// ```
  45. static void initialize({required String androidOnlineLicense,required String iosOnlineLicense}) {
  46. _methodChannel.invokeMethod(initSdkKeys, {'androidOnlineLicense': androidOnlineLicense, 'iosOnlineLicense': iosOnlineLicense});
  47. }
  48. /// Get the version code of the ComPDFKit SDK.
  49. static Future<String> getVersionCode() async {
  50. String versionCode =
  51. await _methodChannel.invokeMethod(ComPDFKit.sdkVersionCode);
  52. return versionCode;
  53. }
  54. /// Get the version information of ComPDFKit SDK.
  55. static Future<String> getSDKBuildTag() async {
  56. String buildTag = await _methodChannel.invokeMethod(ComPDFKit.sdkBuildTag);
  57. return buildTag;
  58. }
  59. /// Enter the local PDF file path, document password (if required),
  60. /// and configuration parameters, and display the PDF document in a new window.
  61. ///
  62. /// **for Samples:**
  63. /// ```dart
  64. /// ComPDFKit.openDocument(
  65. /// 'xxx/compdfkit.pdf',
  66. /// password : '',
  67. /// configuration:CPDFConfiguration())
  68. /// ```
  69. static void openDocument(String document,
  70. {String? password, CPDFConfiguration? configuration}) async {
  71. await _methodChannel.invokeMethod('openDocument', <String, dynamic>{
  72. 'document': document,
  73. 'password': password,
  74. 'configuration': configuration?.toJson()
  75. });
  76. }
  77. /// Retrieve the path of your operating system's temporary directory.
  78. /// Support [Android] and [iOS] only for now.
  79. static Future<Directory> getTemporaryDirectory() async {
  80. final String? path =
  81. await _methodChannel.invokeMethod('getTemporaryDirectory');
  82. if (path == null) {
  83. throw Exception('Unable to get temporary directory');
  84. }
  85. return Directory(path);
  86. }
  87. }