compdfkit.dart 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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:flutter/services.dart';
  9. class ComPDFKit {
  10. static const MethodChannel _methodChannel =
  11. MethodChannel('com.compdfkit.flutter.plugin');
  12. static const initSDK = 'init_sdk';
  13. static const sdkVersionCode = 'sdk_version_code';
  14. static const sdkBuildTag = "sdk_build_tag";
  15. static void init(String key, String secret) async {
  16. _methodChannel.invokeMethod(initSDK, {'key': key, 'secret' : secret});
  17. }
  18. /// get ComPDFKit SDK version code
  19. static Future<String> getVersionCode() async {
  20. String versionCode =
  21. await _methodChannel.invokeMethod(ComPDFKit.sdkVersionCode);
  22. return versionCode;
  23. }
  24. /// get ComPDFKit SDK build tag info
  25. static Future<String> getSDKBuildTag() async {
  26. String buildTag = await _methodChannel.invokeMethod(ComPDFKit.sdkBuildTag);
  27. return buildTag;
  28. }
  29. /// Pass in the local file path of the PDF document and display it within a newly opened view.
  30. static void openDocument(String document,
  31. {String? password}) async {
  32. await _methodChannel.invokeMethod('openDocument', <String, dynamic>{
  33. 'document': document,
  34. 'password': password
  35. });
  36. }
  37. /// Retrieve the temporary directory path of the currently running platform.
  38. /// Currently, only [Android] and [IOS] are supported.
  39. static Future<Directory> getTemporaryDirectory() async {
  40. final String? path =
  41. await _methodChannel.invokeMethod('getTemporaryDirectory');
  42. if (path == null) {
  43. throw Exception('Unable to get temporary directory');
  44. }
  45. return Directory(path);
  46. }
  47. }