Skip to content

Commit

Permalink
(Android) - added dart method mergeAnnotations - importAnnotations to…
Browse files Browse the repository at this point in the history
… 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>
  • Loading branch information
darrenchann and github-actions[bot] authored Aug 23, 2023
1 parent 6de50ab commit 29364c6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions lib/pdftron_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ class PdftronFlutter {
Functions.importAnnotations, <String, dynamic>{Parameters.xfdf: xfdf});
}

/// Merges the given XFDF annotation string to the current document.
static Future<void> mergeAnnotations(String xfdf) {
return _channel.invokeMethod(
Functions.mergeAnnotations, <String, dynamic>{Parameters.xfdf: xfdf});
}

/// Exports the specified annotations in the current document as a XFDF annotation string.
///
/// ```dart
Expand Down
1 change: 1 addition & 0 deletions lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 6 additions & 0 deletions lib/src/document_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ class DocumentViewController {
Functions.importAnnotations, <String, dynamic>{Parameters.xfdf: xfdf});
}

/// Merges the given XFDF annotation string to the current document.
Future<void> mergeAnnotations(String xfdf) {
return _channel.invokeMethod(
Functions.mergeAnnotations, <String, dynamic>{Parameters.xfdf: xfdf});
}

/// Exports the specified annotations in the current document as a XFDF annotation string.
///
/// ```dart
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 29364c6

Please sign in to comment.