@@ -1958,8 +1958,9 @@ - (void)importAnnotations:(NSString *)xfdf resultToken:(FlutterResult)flutterRes
19581958 PTAnnotationManager * const annotationManager = documentController.toolManager .annotationManager ;
19591959
19601960 NSError *updateError = nil ;
1961- const BOOL updateSuccess = [annotationManager updateAnnotationsWithXFDFString: xfdf
1962- error: &updateError];
1961+ const BOOL updateSuccess = [self updateAnnotationsWithXFDFString: xfdf
1962+ error: &updateError
1963+ annotationManager: annotationManager];
19631964 if (!updateSuccess) {
19641965 if (updateError) {
19651966 NSLog (@" Error: There was an error while trying to import annotation command. %@ " , updateError.localizedDescription );
@@ -1970,6 +1971,49 @@ - (void)importAnnotations:(NSString *)xfdf resultToken:(FlutterResult)flutterRes
19701971 }
19711972}
19721973
1974+ - (BOOL )updateAnnotationsWithXFDFString : (NSString *)xfdfString
1975+ error : (NSError * _Nullable __autoreleasing * _Nullable)error
1976+ annotationManager : (PTAnnotationManager *)annotationManager
1977+ {
1978+ PTPDFViewCtrl * const pdfViewCtrl = annotationManager.pdfViewCtrl ;
1979+ if (!pdfViewCtrl) {
1980+ return NO ;
1981+ }
1982+
1983+ [annotationManager willUpdateAnnotationsWithXFDFString: xfdfString];
1984+
1985+ NSError *writeError = nil ;
1986+ const BOOL writeSuccess = [pdfViewCtrl DocLock: YES
1987+ withBlock: ^(PTPDFDoc * _Nullable doc) {
1988+
1989+ PTFDFDoc * const fdfDoc = [PTFDFDoc CreateFromXFDF: xfdfString];
1990+ if (!fdfDoc) {
1991+ return ;
1992+ }
1993+
1994+ [doc FDFUpdate: fdfDoc];
1995+
1996+ // Allow non-standard annotation rotations.
1997+ PTRefreshOptions * const refreshOptions = [[PTRefreshOptions alloc ] init ];
1998+ [refreshOptions SetUseNonStandardRotation: YES ];
1999+
2000+ [doc RefreshAnnotAppearances: refreshOptions];
2001+
2002+ [pdfViewCtrl Update: YES ];
2003+ } error: &writeError];
2004+ if (!writeSuccess) {
2005+ NSLog (@" Error: %@ " , writeError);
2006+ if (error) {
2007+ *error = writeError;
2008+ }
2009+ return NO ;
2010+ }
2011+
2012+ [annotationManager didUpdateAnnotationsWithXFDFString: xfdfString];
2013+
2014+ return YES ;
2015+ }
2016+
19732017- (void )exportAnnotations : (NSString *)annotationList resultToken : (FlutterResult)flutterResult
19742018{
19752019 PTDocumentController *documentController = [self getDocumentController ];
0 commit comments