A package to export any Flutter widget to a PDF-Document, PDF-Page or PDF-File. Further customization of the export process is possible through the export options.
Package selection guidance compiled from public package information, community data, and project usage.
flutter_to_pdf is a Flutter package that enables developers to convert any Flutter widget into a PDF document, page, or file. It supports extensive customization of the export process through configurable options, making it ideal for generating reports, invoices, and printable content. The package works across all major platforms including Android, iOS, Web, macOS, Windows, and Linux, ensuring consistent output regardless of the target environment.
Use cases
Generating printable reports
Creating invoices and receipts
Exporting forms and documents
Producing PDFs from dynamic UI
Sharing Flutter-generated content as PDFs
Key features
Convert any Flutter widget to PDF
Customizable export options
Cross-platform support
Support for multiple output formats
High-quality rendering
Easy integration with existing code
Suitable for
Developers building document-heavy apps
Apps requiring print-ready outputs
Business applications needing PDF generation
Educational tools with downloadable content
Web and mobile apps with reporting features
Considerations
Performance may vary with complex widgets
Large PDFs can impact memory usage
Requires careful handling of fonts and images
Limited native PDF editing capabilities
May need additional configuration for advanced layouts
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
The FlutterToPDF package lets you export any Flutter widget to PDF Documents and is written natively in Dart.
Installing
Depend on it
Run this command:
$ flutter pub add flutter_to_pdf
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):
dependencies:flutter_to_pdf:^0.4.1
Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.
Create an instance of the ExportDelegate, wrap your widget with a ExportFrame widget and provide a frameId, as well as the exportDelegate.
When you want to export the widget call the desired export function (either exportToPdfDocument, exportToPdfPage or exportToPdfWidget) and pass in the frameId.
// create instance of ExportDelegatefinalExportDelegate exportDelegate = ExportDelegate();
ExportFrame(
frameId: 'someFrameId',
exportDelegate: exportDelegate,
child: SomeWidget(), // the widget you want to export
)
// export the frame to a PDF Documentfinal pdf = await exportDelegate.exportToPdfDocument('someFrameId');
// export the frame to a PDF Pagefinal page = await exportDelegate.exportToPdfPage('someFrameId');
// export the frame to a PDF Widgetfinal widget = await exportDelegate.exportToPdfWidget('someFrameId');
Note: If you wish to use types on the variables pdf, page and widget, you can use the Document, Page and Widget classes provided by PDF-package.
Custom TTF Fonts
If the widget you want to export contains any custom TTF fonts, you must provide the used ttfFonts to the ExportDelegate.
If the widget you want to export contains any TextField, TextFormField or Checkbox, a uniqueKey must be provided to each TextField, TextFormField and Checkbox.
If the widget you want to export contains any custom widgets like CustomPaint or Charts, the widgets you want to export must be wrapped in a CaptureWrapper widget. Furthermore, the CaptureWrapper must have a uniqueKey.
These widgets will then be captured as an image and exported to the PDF Document.
The ExportDelegate´s options can also be overriden using the named optional parameter overrideOptions in the export function.
finalExportOptions options = ExportOptions(
pageFormatOptions: PageFormatOptions.a3(),
textFieldOptions: TextFieldOptions.uniform(
interactive: false,
),
checkboxOptions: CheckboxOptions.uniform(
interactive: false,
),
);
finalExportDelegate exportDelegate = ExportDelegate(options: options);
finalExportOptions overrideOptions = ExportOptions(
pageFormatOptions: PageFormatOptions.a4(),
textFieldOptions: TextFieldOptions.uniform(
interactive: true,
),
checkboxOptions: CheckboxOptions.uniform(
interactive: true,
),
);
// export the frame to a PDF Document, using the override optionsfinal pdf = await exportDelegate.exportToPdfDocument('someFrameId', overrideOptions: overrideOptions);
// export the frame to a PDF Page, using the override optionsfinal page = await exportDelegate.exportToPdfPage('someFrameId', overrideOptions: overrideOptions);
// export the frame to a PDF Widget, using the override optionsfinal widget = await exportDelegate.exportToPdfWidget('someFrameId', overrideOptions: overrideOptions);
Page Format Options
The PageFormatOptions class can be used to customize the page format of the exported PDF Document.
All constructors have an optional parameter clip which can be used to define if the content of the page should be clipped to the page format. The default value is true.
For the PageFormatOptions class there are several predefined constructors available:
PageFormatOptions.a3 - A3 page format
PageFormatOptions.a4 - A4 page format
PageFormatOptions.a5 - A5 page format
PageFormatOptions.a6 - A6 page format
PageFormatOptions.letter - Letter page format
PageFormatOptions.legal - Legal page format
PageFormatOptions.roll57 - Roll57 page format
PageFormatOptions.roll80 - Roll80 page format
PageFormatOptions.custom - Custom page format
The custom page format can be used to define a custom page format. It therefore requires at least the width parameter, and has the following optional parameters: height, marginTop, marginBottom, marginLeft, marginRight and marginAll.
Text Field Options
The TextFieldOptions class can be used to customize the text fields of the exported PDF Document.
All constructors have an optional parameter interactive which can be used to define if the text fields should be interactive. The default value is true.
If interactive is set to false, the text fields will be rendered as Text.
For the TextFieldOptions class there are several predefined constructors available:
TextFieldOptions.uniform - Uniform text field options
The uniform text field options can be used to define a uniform TextStyle for all text fields. It therefore has an optional parameter textstyle which can be used to define a custom TextStyle for all text fields.
TextFieldOptions.individual - Individual text field options
The individual text field options can be used to define an individual TextStyle for each text field. It has an optional parameter styleMap which maps the textfield´s Key to a TextStyle. Note: The TextField therefore requires a Key to be able to map the TextStyle to the text field.
TextFieldOptions.none - No text field options
The text fields will be interactive and will be styled as found in the widget tree.
Checkbox Options
The CheckboxOptions class can be used to customize the checkboxes of the exported PDF Document.
All constructors have an optional parameter interactive which can be used to define if the checkboxes should be interactive. The default value is true.
If interactive is set to false, the checkboxes will be rendered as a Container and will not be clickable.
For the CheckboxOptions class there are several predefined constructors available:
The uniform checkbox options can be used to define a uniform BoxDecoration for all checkboxes. It therefore has an optional parameter boxDecoration which can be used to define a custom BoxDecoration for all checkboxes.
The individual checkbox options can be used to define an individual BoxDecoration for each checkbox. It has an optional parameter decorationMap which maps the checkbox´s Key to a BoxDecoration. Note: The Checkbox therefore requires a Key to be able to map the BoxDecoration to the checkbox.
CheckboxOptions.none - No checkbox options
The checkboxes will be interactive and will be styled as found in the widget tree.