flutter_quill_to_pdf 2.3.7
flutter_quill_to_pdf: ^2.3.7 copied to clipboard
Create PDF'S using deltas from Quill, with configurable attributes, fonts, and custom pdf widgets
📖 Flutter Quill to PDF #
Flutter Quill to PDF is a powerful package designed to convert documents created with Flutter Quill (based on Deltas) into high-quality PDF files. This package offers a wide range of customization options, allowing developers to adjust page formatting (width, height, and margins), customize fonts, text styles, and add elements such as images, videos, lists, blockquotes, and code blocks. Additionally, it supports the generation of custom widgets to integrate PDF content directly into the Flutter user interface.
Show/Hide screenshots
Content used to generate the PDF

PDF generated

Tip
If you are using the version v2.2.9 or a minor version, see the breaking changes that were maded in v2.3.0
📚 Resources #
code-block customization blockquote customization theme customization header customization
🔎 Creating your PDF file #
📎 First: personalize the settings of the page (height
, width
and margins
)
final PDFPageFormat pageFormat = PDFPageFormat(
width: ..., //max width of the page
height: ..., //max height of the page,
marginTop: ...,
marginBottom: ...,
marginLeft: ...,
marginRight: ...,
);
// or use
final PDFPageFormat pageFormat = PDFPageFormat.all(
width: ..., //max width of the page
height: ..., //max height of the page,
margin: ..., //will set the property to the others margins
);
⚒️ Second: create your PDFConverter
import 'package:flutter_quill_to_pdf/flutter_quill_to_pdf.dart':
final pdfConverter = PDFConverter(
document: _quillController.document.toDelta(),
pageFormat: pageFormat, // pass your page format here
// optional params
backMatterDelta: null,
frontMatterDelta: null,
// set a default Direction to your pdf widgets
textDirection: Directionality.of(context),
// if you support web platform, you will need to pass this param,
// since fetching images in web works differently
isWeb: kIsWeb,
themeData: null, // your custom theme for the document
listTypeWidget: ListTypeWidget.stable, // or ListTypeWidget.modern
documentOptions: DocumentOptions(
title: 'My fantastic document',
author: 'Me',
creator: 'Me',
subject: 'Another fantastic document',
keywords: 'my, key, words',
producer: 'Me',
version: PdfVersion.pdf_1_5,
orientation: pw.PageOrientation.portrait,
mode: PdfPageMode.thumbs,
),
// create a custom leading for your lists
listLeadingBuilder: (String type, int level, Object? args) => null,
customHeadingSizes: [50, 45, 40, 35, 30], // override default heading sizes
// code-block
enableCodeBlockHighlighting: true,
isLightCodeBlockTheme: false,
// your custom theme for code-block (see code-block customization resource)
customCodeHighlightTheme: <String, pw.TextStyle>{},
codeBlockBackgroundColor: null, // override default implementation
codeBlockNumLinesTextStyle: null, // override default implementation
codeBlockFont: null, // override default implementation
inlineCodeStyle: null, // override default implementation
// blockquote
blockquoteTextStyle: null, // override default implementation
blockquotePadding: null, // override default implementation
blockquoteBoxDecoration: null, // override default implementation
// custom widgets
onDetectBlockquote: (Paragraph paragraph, Map<String, dynamic>? blockAttributes, [Object? args]) {
return YourPdfWidget();
},
onDetectCodeBlock: null,
onDetectVideoBlock: null,
fallbacks: <pw.Font>[], // here you can put all your pdf font fallbacks
onRequestFontFamily: (FontFamilyRequest familyRequest) {
return FontFamilyResponse(
fontNormalV: <anyFontThatYouWant>,
boldFontV: familyRequest.isBold ? <yourBoldFontFamily> : null,
italicFontV: familyRequest.isItalic ? <yourItalicFontFamily> : null,
boldItalicFontV: familyRequest.isItalic && familyRequest.isBold ? <yourBoldItalicFontFamily> : null,
fallbacks: const <pw.Font>[],
);
},
);
📝 Creating the PdfDocument/widgets: #
import 'dart:io';
import 'package:flutter_quill_to_pdf/flutter_quill_to_pdf.dart';
import 'package:pdf/pdf.dart';
// return a pdf Document
final doc = await pdfConverter.createDocument();
// Generate the widgets without adding them to a pdf document
final pw.Widget? pwWidget = await pdfConverter.generateWidget(
maxWidth: pwWidgetWidth,
maxHeight: pwWidgetHeight,
);
// with this, we can use doc.save() to write the bytes into a File in a Storage Path
Supported Attributes #
Inlines
- Size
- Bold
- Link
- Color
- Italic
- Underline
- inline code
- Font family
- Strikethrough
- Background Color
- Superscript/Subscript (being planned)
Blocks
Combinable with other Block/Non block Attributes
- Align
- Indent
- Direction
- Line-height
Exclusives
- Header
- Code-block
- Blockquote
- Embed image (Base64, URL, and common storage paths)
- Embed video (by default, just the URL of the video will be pasted as a text)
- List (Multilevel List too)
- Ordered List
- Bullet List
- ✅ CheckBox List
Contributing #
We greatly appreciate your time and effort.
To keep the project consistent and maintainable, we have a few guidelines that we ask all contributors to follow. These guidelines help ensure that everyone can understand and work with the code easier.
See Contributing for more details.