compdfkit.dart 3.9 KB

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