openPDF method
Future<PdfAnnotationResult>
openPDF({
- required String filePath,
- String? savePath,
- PDFAnnotationConfig? config,
override
Opens filePath in the native annotation editor.
See FlutterPdfAnnotations.openPDF for full documentation.
Implementation
@override
Future<PdfAnnotationResult> openPDF({
required String filePath,
String? savePath,
PDFAnnotationConfig? config,
}) async {
final resolvedSavePath = savePath ?? _tempSavePath();
try {
File(resolvedSavePath).parent.createSync(recursive: true);
} catch (e) {
return PdfAnnotationResult.error(
'Cannot create save directory: $e');
}
final args = <String, dynamic>{
'filePath': filePath,
'savePath': resolvedSavePath,
...?config?.toMap(),
};
final tempImagePaths = <String>[];
if (config?.imagesToInsert != null && config!.imagesToInsert!.isNotEmpty) {
try {
tempImagePaths.addAll(await _saveImagesToTemp(config.imagesToInsert!));
} catch (e) {
return PdfAnnotationResult.error('Failed to prepare images: $e');
}
if (tempImagePaths.isNotEmpty) args['imagePaths'] = tempImagePaths;
}
try {
return await _invoke(args);
} finally {
_cleanupTempImages(tempImagePaths);
}
}