compdfkit.dart 3.8 KB

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