Skip to content

Commit 73af623

Browse files
[iOS] Match Android implementation of importAnnotations (#682)
* Add replace parameter to importAnnotations function on iOS * Update documentation * Updating package version --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 16504cf commit 73af623

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

API.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2580,7 +2580,7 @@ Parameters:
25802580
Name | Type | Description
25812581
--- | --- | ---
25822582
xfdf | string | annotation string in XFDF format for import
2583-
replace | boolean | whether to replace existing form and annotation data with those imported from the XFDF string (Android only)
2583+
replace | boolean | whether to replace existing form and annotation data with those imported from the XFDF string
25842584

25852585
Returns a Promise.
25862586
Promise Parameters:

ios/RNTPTDocumentView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ static NSString * const PTSignaturesManager_signatureDirectory = @"PTSignaturesM
572572

573573
- (nullable NSString *)exportAnnotationsWithOptions:(NSDictionary *)options;
574574

575-
- (nullable NSArray<NSDictionary *> *)importAnnotations:(NSString *)xfdfString;
575+
- (nullable NSArray<NSDictionary *> *)importAnnotations:(NSString *)xfdfString replace:(BOOL)replace;
576576

577577
- (void)flattenAnnotations:(BOOL)formsOnly;
578578

ios/RNTPTDocumentView.m

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ - (NSString *)exportAnnotationsWithOptions:(NSDictionary *)options
13531353
return nil;
13541354
}
13551355

1356-
- (nullable NSArray<NSDictionary *> *)importAnnotations:(NSString *)xfdfString
1356+
- (nullable NSArray<NSDictionary *> *)importAnnotations:(NSString *)xfdfString replace:(BOOL)replace
13571357
{
13581358
PTDocumentBaseViewController *documentViewController = self.currentDocumentViewController;
13591359
PTPDFViewCtrl *pdfViewCtrl = documentViewController.pdfViewCtrl;
@@ -1369,12 +1369,24 @@ - (NSString *)exportAnnotationsWithOptions:(NSDictionary *)options
13691369
return nil;
13701370
}
13711371

1372-
PTAnnotationManager * const annotationManager = documentViewController.toolManager.annotationManager;
1372+
if (self.collaborationManager != nil) {
1373+
[self.collaborationManager importAnnotationsWithXFDFString:xfdfString];
1374+
return [self getAnnotationFromXFDF:xfdfString];
1375+
}
13731376

1374-
const BOOL updateSuccess = [annotationManager updateAnnotationsWithXFDFString:xfdfString
1375-
error:&error];
1376-
if (!updateSuccess || error) {
1377-
@throw [NSException exceptionWithName:NSGenericException reason:error.localizedFailureReason userInfo:error.userInfo];
1377+
[pdfViewCtrl DocLock:YES withBlock:^(PTPDFDoc * _Nullable doc) {
1378+
PTFDFDoc *fdfDoc = [PTFDFDoc CreateFromXFDF:xfdfString];
1379+
if (replace) {
1380+
[doc FDFUpdate:fdfDoc];
1381+
} else {
1382+
[doc FDFMerge:fdfDoc];
1383+
}
1384+
[pdfViewCtrl Update:YES];
1385+
} error:&error];
1386+
1387+
if (error) {
1388+
NSLog(@"Error: There was an error while trying to import annotations. %@", error.localizedDescription);
1389+
return nil;
13781390
}
13791391

13801392
return [self getAnnotationFromXFDF:xfdfString];

ios/RNTPTDocumentViewManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ - (void)importAnnotationCommandForDocumentViewTag:(NSNumber *)tag xfdfCommand:(N
11301130
{
11311131
RNTPTDocumentView *documentView = self.documentViews[tag];
11321132
if (documentView) {
1133-
return [documentView importAnnotations:xfdfString];
1133+
return [documentView importAnnotations:xfdfString replace:replace];
11341134
} else {
11351135
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Unable to find DocumentView for tag" userInfo:nil];
11361136
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-native-pdftron",
33
"title": "React Native Pdftron",
4-
"version": "3.0.3-36",
4+
"version": "3.0.3-37",
55
"description": "React Native Pdftron",
66
"main": "./lib/index.js",
77
"typings": "index.ts",

0 commit comments

Comments
 (0)