How to use Save As for PDFs in Flutter
It’s not uncommon for customers to want a setup where a document is read-only but users can still edit it and then use the Save As functionality to save the modified document to a new location. Nutrient supports saving documents with the Save As functionality.
After displaying a document on Flutter using either NutrientView
(opens in a new tab) or Nutrient.present()
(opens in a new tab), Save As can be implemented by following these steps:
- Ensuring
disableAutosave
is set totrue
in the configuration. - Calling the
processAnnotations
API on eitherNutrientViewController
(opens in a new tab) or theNutrient
(opens in a new tab) plugin when a custom FlutterButton
widget is pressed.
NutrientView and NutrientViewController
The code for this on Dart looks something like this:
@overrideWidget build(BuildContext context) { // ... return Scaffold( // ... body: Column(children: [ Expanded( child: NutrientView( document: documentPath, configuration: configuration, onViewCreated: onPlatformViewCreated), SizedBox( child: ElevatedButton( onPressed: () async { // Ensure that the path for the new document is a writable path. // You can use a package like https://pub.dev/packages/filesystem_picker to allow users to select the directory and name of the file to save. final newDocumentPath = await getExportPath( 'PDFs/Embedded/new_pdf_document.pdf');
await nutrientViewController.processAnnotations( 'all', 'embed', newDocumentPath);
print( 'Document has been saved to $newDocumentPath'); }, child: const Text('Save Document As')) ))] ));// ...}
// ...
// This method is part of the custom widget's class. Future<void> onPlatformViewCreated(controller) async { nutrientViewController = controller; }
Save As is currently only available on iOS. Support for Save As on Android is coming soon.