From 29364c6ed585af71d53aef9ec322336f987c493c Mon Sep 17 00:00:00 2001 From: Darren Chan Date: Wed, 23 Aug 2023 16:05:56 -0700 Subject: [PATCH] (Android) - added dart method mergeAnnotations - importAnnotations to merge instead of update (#302) * mergeAnnotations - android mergeAnnotations added (feature parity with RN) * Updating package version * Updating pubspec.yaml * Updating package version * Update CHANGELOG.md * Updating pubspec.yaml * Updating package version * Update CHANGELOG.md * Updating pubspec.yaml * Updating package version * Update CHANGELOG.md * Updating pubspec.yaml * Updating package version * fix branch * update document_view.dart * Updating pubspec.yaml * Updating package version --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 6 ++++++ .../pdftronflutter/helpers/PluginUtils.java | 21 ++++++++++++++++--- lib/pdftron_flutter.dart | 6 ++++++ lib/src/constants.dart | 1 + lib/src/document_view.dart | 6 ++++++ pubspec.yaml | 2 +- 6 files changed, 38 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ac7d56c..e57f97c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.0.0-18 - August 23, 2023 +- mergeAnnotations() + +# 1.0.0-17 - August 8, 2023 +- added eraser to PTToolKey (iOS) + # 1.0.0-16 - August 2, 2023 - Update Android to v10.3.0 diff --git a/android/src/main/java/com/pdftron/pdftronflutter/helpers/PluginUtils.java b/android/src/main/java/com/pdftron/pdftronflutter/helpers/PluginUtils.java index b9b179db..f2efc2d5 100644 --- a/android/src/main/java/com/pdftron/pdftronflutter/helpers/PluginUtils.java +++ b/android/src/main/java/com/pdftron/pdftronflutter/helpers/PluginUtils.java @@ -304,6 +304,7 @@ public class PluginUtils { public static final String FUNCTION_SET_FLAG_FOR_FIELDS = "setFlagForFields"; public static final String FUNCTION_SET_VALUES_FOR_FIELDS = "setValuesForFields"; public static final String FUNCTION_IMPORT_ANNOTATIONS = "importAnnotations"; + public static final String FUNCTION_MERGE_ANNOTATIONS = "mergeAnnotations"; public static final String FUNCTION_EXPORT_ANNOTATIONS = "exportAnnotations"; public static final String FUNCTION_FLATTEN_ANNOTATIONS = "flattenAnnotations"; public static final String FUNCTION_DELETE_ANNOTATIONS = "deleteAnnotations"; @@ -2175,13 +2176,23 @@ public static void onMethodCall(MethodCall call, MethodChannel.Result result, Vi checkFunctionPrecondition(component); String xfdf = call.argument(KEY_XFDF); try { - importAnnotations(xfdf, result, component); + importAnnotations(xfdf, true, result, component); } catch (PDFNetException ex) { ex.printStackTrace(); result.error(Long.toString(ex.getErrorCode()), "PDFTronException Error: " + ex, null); } break; } + case FUNCTION_MERGE_ANNOTATIONS: { + checkFunctionPrecondition(component); + String xfdf = call.argument(KEY_XFDF); + try { + importAnnotations(xfdf, false, result, component); + } catch (PDFNetException ex) { + ex.printStackTrace(); + result.error(Long.toString(ex.getErrorCode()), "PDFTronException Error: " + ex, null); + } + } case FUNCTION_EXPORT_ANNOTATIONS: { checkFunctionPrecondition(component); String annotationList = call.argument(KEY_ANNOTATION_LIST); @@ -2856,7 +2867,7 @@ private static void groupAnnotations(MethodCall call, MethodChannel.Result resul } } - private static void importAnnotations(String xfdf, MethodChannel.Result result, ViewerComponent component) throws PDFNetException { + private static void importAnnotations(String xfdf, boolean replace, MethodChannel.Result result, ViewerComponent component) throws PDFNetException { PDFViewCtrl pdfViewCtrl = component.getPdfViewCtrl(); PDFDoc pdfDoc = component.getPdfDoc(); if (null == pdfViewCtrl || null == pdfDoc || null == xfdf) { @@ -2886,7 +2897,11 @@ private static void importAnnotations(String xfdf, MethodChannel.Result result, FDFDoc fdfDoc = FDFDoc.createFromXFDF(xfdf); - pdfDoc.fdfUpdate(fdfDoc); + if (replace) { + pdfDoc.fdfUpdate(fdfDoc); + } else { + pdfDoc.fdfMerge(fdfDoc); + } pdfDoc.refreshAnnotAppearances(); pdfViewCtrl.update(true); diff --git a/lib/pdftron_flutter.dart b/lib/pdftron_flutter.dart index 42431ee9..50fcbfcf 100644 --- a/lib/pdftron_flutter.dart +++ b/lib/pdftron_flutter.dart @@ -62,6 +62,12 @@ class PdftronFlutter { Functions.importAnnotations, {Parameters.xfdf: xfdf}); } + /// Merges the given XFDF annotation string to the current document. + static Future mergeAnnotations(String xfdf) { + return _channel.invokeMethod( + Functions.mergeAnnotations, {Parameters.xfdf: xfdf}); + } + /// Exports the specified annotations in the current document as a XFDF annotation string. /// /// ```dart diff --git a/lib/src/constants.dart b/lib/src/constants.dart index 3df2d655..b91948b9 100644 --- a/lib/src/constants.dart +++ b/lib/src/constants.dart @@ -11,6 +11,7 @@ class Functions { /// Android only static const getSavedSignatureJpgFolder = "getSavedSignatureJpgFolder"; static const importAnnotations = "importAnnotations"; + static const mergeAnnotations = "mergeAnnotations"; static const exportAnnotations = "exportAnnotations"; static const flattenAnnotations = "flattenAnnotations"; static const deleteAnnotations = "deleteAnnotations"; diff --git a/lib/src/document_view.dart b/lib/src/document_view.dart index b115b023..49e61c5a 100644 --- a/lib/src/document_view.dart +++ b/lib/src/document_view.dart @@ -90,6 +90,12 @@ class DocumentViewController { Functions.importAnnotations, {Parameters.xfdf: xfdf}); } + /// Merges the given XFDF annotation string to the current document. + Future mergeAnnotations(String xfdf) { + return _channel.invokeMethod( + Functions.mergeAnnotations, {Parameters.xfdf: xfdf}); + } + /// Exports the specified annotations in the current document as a XFDF annotation string. /// /// ```dart diff --git a/pubspec.yaml b/pubspec.yaml index c23a0814..ddbdc562 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: pdftron_flutter description: A convenience wrapper to build Flutter apps that use the PDFTron mobile SDK for smooth, flexible, and stand-alone document viewing. -version: 1.0.1-17 +version: 1.0.1-18 homepage: https://www.pdftron.com repository: https://github.com/PDFTron/pdftron-flutter issue_tracker: https://github.com/PDFTron/pdftron-flutter/issues