compdfkit.dart 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /// Copyright © 2014-2024 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 initSdkKeys = 'init_sdk_keys';
  15. static const sdkVersionCode = 'sdk_version_code';
  16. static const sdkBuildTag = "sdk_build_tag";
  17. /// Please enter your ComPDFKit license to initialize the ComPDFKit SDK.<br/>
  18. /// This method is used for offline license authentication.
  19. /// In version **1.13.0**, we have introduced a brand-new online authentication licensing scheme.
  20. /// By default, the ComPDFKit SDK performs online authentication.
  21. /// If you are unsure about the type of your license, please contact the [ComPDFKit team.](https://www.compdf.com/support).
  22. ///
  23. /// **samples:**<br/>
  24. /// ```dart
  25. /// ComPDFKit.init('your compdfkit license')
  26. /// ```
  27. static void init(String key) async {
  28. _methodChannel.invokeMethod(initSDK, {'key': key});
  29. }
  30. /// Please enter your ComPDFKit license to initialize the ComPDFKit SDK.<br/>
  31. /// This method is used for online license authentication
  32. /// In version **1.13.0**, we have introduced a brand-new online authentication licensing scheme.
  33. /// By default, the ComPDFKit SDK performs online authentication.
  34. /// If you obtained your ComPDFKit License before the release of version 1.13.0, please use [ComPDFKit.init] <br/>
  35. /// If you are unsure about the type of your license, please contact the [ComPDFKit team.](https://www.compdf.com/support).
  36. ///
  37. /// **samples:**<br/>
  38. /// **online auth**
  39. /// ```dart
  40. /// ComPDFKit.initialize(androidOnlineLicense : 'your android platform compdfkit license', iosOnlineLicense: 'your ios platform compdfkit license')
  41. /// ```
  42. static void initialize({required String androidOnlineLicense,required String iosOnlineLicense}) {
  43. _methodChannel.invokeMethod(initSdkKeys, {'androidOnlineLicense': androidOnlineLicense, 'iosOnlineLicense': iosOnlineLicense});
  44. }
  45. /// Get the version code of the ComPDFKit SDK.
  46. static Future<String> getVersionCode() async {
  47. String versionCode =
  48. await _methodChannel.invokeMethod(ComPDFKit.sdkVersionCode);
  49. return versionCode;
  50. }
  51. /// Get the version information of ComPDFKit SDK.
  52. static Future<String> getSDKBuildTag() async {
  53. String buildTag = await _methodChannel.invokeMethod(ComPDFKit.sdkBuildTag);
  54. return buildTag;
  55. }
  56. /// Enter the local PDF file path, document password (if required),
  57. /// and configuration parameters, and display the PDF document in a new window.
  58. ///
  59. /// **for Samples:**
  60. /// ```dart
  61. /// ComPDFKit.openDocument(
  62. /// 'xxx/compdfkit.pdf',
  63. /// password : '',
  64. /// configuration:CPDFConfiguration())
  65. /// ```
  66. static void openDocument(String document,
  67. {String? password, CPDFConfiguration? configuration}) async {
  68. await _methodChannel.invokeMethod('openDocument', <String, dynamic>{
  69. 'document': document,
  70. 'password': password,
  71. 'configuration': configuration?.toJson()
  72. });
  73. }
  74. /// Retrieve the path of your operating system's temporary directory.
  75. /// Support [Android] and [iOS] only for now.
  76. static Future<Directory> getTemporaryDirectory() async {
  77. final String? path =
  78. await _methodChannel.invokeMethod('getTemporaryDirectory');
  79. if (path == null) {
  80. throw Exception('Unable to get temporary directory');
  81. }
  82. return Directory(path);
  83. }
  84. }