compdfkit.dart 3.9 KB

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