Use Save as for PDFs in Flutter
Use Save as when users need to edit a document without changing the original file. Nutrient Flutter SDK can save the modified document to a new location.
Implement Save as
After you display a document with NutrientDocumentView, implement Save as with these steps:
- Set
disableAutosavetotruein the configuration so the SDK doesn’t change the original file. - Call
save(outputPath:)oncontroller.documentwhen the user selects a custom FlutterButtonwidget. Refer to thesave(opens in a new tab) API reference for details.
The following Dart example saves the current document state to a new writable path:
@overrideWidget build(BuildContext context) { return Scaffold( body: Column(children: [ Expanded( child: NutrientDocumentView( documentPath: documentPath, configuration: const NutrientViewConfiguration(disableAutosave: true), onControllerReady: (controller) => _controller = controller, ), ), 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');
final saved = await _controller!.document.save(outputPath: newDocumentPath);
if (saved) { print('Document has been saved to $newDocumentPath'); } }, child: const Text('Save Document As'), ), ), ]), );}The original document keeps its unsaved changes in the viewer. The copy at outputPath contains the current state of the document. For a complete runnable example, open save_as_example in the Catalog app.
On web, there’s no file system to save to, so save(outputPath:) throws UnsupportedError. Use exportPdf() to get the document bytes and pass them to the browser download flow instead. Refer to the export PDF(opens in a new tab) API reference for details.
Save as also differs from the legacy method-channel implementation.
The legacy processAnnotations workaround for Save as is part of the deprecated method-channel API. Use save(outputPath:) instead. Refer to the migration guide for details.