How to create and edit PDFs in Flutter with Nutrient
Table of contents
With the Nutrient Flutter PDF SDK you can both create and edit PDFs from a single Dart codebase:
- Generate PDFs from blank pages, patterns, images, or HTML with
Nutrient.generatePdf. - Display documents in the
NutrientViewwidget and let users annotate and edit through the built-in UI. - Add, read, and remove annotations programmatically with the annotation model classes.
Start a free trial or launch the demo to try it.
This post shows how to create and edit PDFs in a Flutter app using the Nutrient Flutter PDF SDK. You’ll generate documents programmatically, display them in a viewer, and add annotations — all from one Dart codebase that runs on iOS, Android, and web.
Flutter is a free, open source framework from Google for building cross-platform apps from a single codebase.
The Nutrient Flutter PDF library
Nutrient offers a commercial Flutter PDF library that ships with a range of out-of-the-box features, including:
- A customizable viewer UI that drops into your app as a widget.
- Tools for annotating documents, filling PDF forms, and signing.
- PDF generation from blank pages, images, and HTML.
- Support for multiple file types — from image files (JPG, PNG, and TIFF) to PDF documents.
- Active development with regular updates and fixes.
Setting up the SDK
Add the dependency to your project:
flutter pub add nutrient_flutterThen complete the platform setup — on Android, set the base activity to FlutterAppCompatActivity; on iOS, set the deployment target to 16.0. For the full step-by-step configuration, follow the getting started on Flutter guide.
Since version 3.9.0, the SDK must be initialized with a license key before use. Pass null to run in trial mode (this shows a watermark):
import 'package:flutter/material.dart';import 'package:nutrient_flutter/nutrient_flutter.dart';
void main() { WidgetsFlutterBinding.ensureInitialized();
// Pass `null` to use the trial version. Nutrient.initialize(androidLicenseKey: null, iosLicenseKey: null);
runApp(const MyApp());}Generating a PDF
The Nutrient.generatePdf method creates a document from a list of NewPage(opens in a new tab) objects and writes it to an output path. Each NewPage can be a blank page, a pattern, an image, or a page from an existing document.
Blank pages and patterns
Create a NewPage with NewPage.fromPattern, passing a PagePattern(opens in a new tab) (such as PagePattern.blank) and an optional page size:
List<NewPage> pages = [ // A blank A5 page. NewPage.fromPattern(PagePattern.blank, pageSize: PageSize.a5),];
final tempDir = await Nutrient.getTemporaryDirectory();final outputPath = '${tempDir.path}/generated.pdf';
var filePath = await Nutrient.generatePdf(pages, outputPath);
// Open the generated document in the viewer.await Nutrient.present(filePath!);Nutrient also ships predefined patterns — PagePattern.dots5mm, PagePattern.grid5mm, and PagePattern.line5mm — for dotted, grid, and lined pages.

From images
To turn an image into a PDF page, wrap it in a PdfImagePage(opens in a new tab) and pass it to NewPage.fromImage:
File img = File('<readable-image-path>');
List<NewPage> pages = [ NewPage.fromImage(PdfImagePage.fromUri(img.uri, PagePosition.center)),];
var filePath = await Nutrient.generatePdf(pages, outputPath);From HTML
You can also render an HTML string (or a URI) straight to a PDF:
const html = '<html><body><h1>Invoice</h1><p>Generated with Nutrient.</p></body></html>';
String? generatedPdf = await Nutrient.generatePdfFromHtmlString(html, outputPath);Displaying and editing a PDF
To show a document, add the NutrientView widget to your screen. The widget includes a full editing UI — users can annotate, fill forms, and sign without any extra code:
import 'package:nutrient_flutter/nutrient_flutter.dart';
Scaffold( body: NutrientView( documentPath: 'file:///path/to/document.pdf', ),);Adding annotations programmatically
Beyond the built-in UI, you can add, read, and remove annotations in code using the annotation model classes. Once you have a reference to the loaded PdfDocument, add an annotation with addAnnotation:
// Create a link annotation pointing to a URL.final linkAnnotation = LinkAnnotation( id: 'link-annotation-1', bbox: [50.0, 700.0, 200.0, 30.0], pageIndex: 0, action: UriAction(uri: 'https://nutrient.io'),);
await document.addAnnotation(linkAnnotation);Read the annotations on a page with getAnnotations, and remove one with removeAnnotation:
List<Annotation> annotations = await document.getAnnotations(0, AnnotationType.all);
if (annotations.isNotEmpty) { await document.removeAnnotation(annotations[0]);}For the full list of annotation types and how to obtain the document reference from the viewer, see the annotations guide.
Filling forms and signing
The same document supports interactive PDF forms and electronic signatures: Users can fill and sign through the NutrientView UI, and you can read or write form field values programmatically — useful for prefilling a form or exporting submitted data to your backend. Cryptographic digital signatures aren’t bridged in the Flutter SDK; they’re applied through the native iOS, Android, or Web layer.
Open source options vs. Nutrient
If you only need to generate or display PDFs, Flutter has capable open source packages:
pdfandprintingbuild PDFs from a widget-style layout and then preview, print, or share them. They’re a good fit when you generate documents like invoices or reports but don’t need to open and edit arbitrary PDFs.flutter_pdfviewandpdfxrender existing PDFs for read-only viewing.
What these libraries don’t cover is everything after viewing — interactive annotation editing, form filling, electronic signatures (with cryptographic digital signing available through the native iOS, Android, or Web SDKs), redaction, and a configurable viewer UI. Reach for the Nutrient Flutter PDF SDK when document interaction is core to your app, or when you want generation, viewing, and editing from one maintained SDK with commercial support. For simple, single-purpose generate-or-view tasks, an open source package may be all you need.
Conclusion
In this post, you generated PDFs from blank pages, images, and HTML; displayed them in the NutrientView widget; and added annotations programmatically with the Nutrient Flutter PDF SDK. From here, the same SDK handles forms, signing, and redaction across iOS, Android, and web.
If you run into any issues, reach out to our Support team. To see the SDK in action, check out our demo or start a free trial.
FAQ
Use the Nutrient Flutter PDF SDK’s Nutrient.generatePdf method. Pass it a list of NewPage objects — built from blank pages, patterns, images, or HTML — and an output path, and it writes the PDF to disk.
Yes. The NutrientView widget includes a built-in editor so users can annotate, fill forms, and sign. You can also add, read, and remove annotations programmatically using the SDK’s annotation model classes.
The SDK runs on iOS, Android, and web from a single Dart codebase, with native rendering on each platform.
Yes. Use Nutrient.generatePdfFromHtmlString to render an HTML string to a PDF, or Nutrient.generatePdfFromHtmlUri to render from a URI.
Related reading
- How to build a Flutter PDF viewer — Focused on displaying PDFs in Flutter
- How to build a React Native PDF viewer — The same workflow for React Native