Overview
The PDF Export plugin enables converting AppFlowy Editor documents to PDF files. It works by first converting the document to HTML/Markdown, then rendering it as PDF using thepdf package.
Installation
The PDF encoder is included with AppFlowy Editor and requires thepdf package:
Basic Usage
Converting Document to PDF
Font Configuration
PDF rendering requires font files for proper text display:Loading Fonts
Creating the Encoder
Supported Elements
The PDF encoder supports these document elements:Block Elements
- Headings: H1 through H6 with appropriate sizing
- Paragraphs: Regular text blocks
- Lists:
- Bulleted lists
- Numbered lists
- Todo lists (with checkboxes)
- Tables: Full table support with borders
- Images: Network and local images
- Block quotes: Rendered as quoted sections
Text Formatting
- Bold:
<b>,<strong> - Italic:
<i>,<em> - Underline:
<u> - Strikethrough:
<del>,<s> - Links: Rendered in blue with underline
- Code: Inline code with gray background
- Colors: Text and background colors from CSS
Implementation Details
Conversion Pipeline
The PDF encoder uses a two-step process:- Markdown to HTML: Convert markdown to HTML using the
markdownpackage - HTML to PDF: Parse HTML and render as PDF widgets
/lib/src/plugins/pdf/html_to_pdf_encoder.dart:24-56:
Heading Sizes
Headings are sized according to their level (fromhtml_to_pdf_encoder.dart:657-682):
- H1: 32pt
- H2: 28pt
- H3: 20pt
- H4: 17pt
- H5: 14pt
- H6: 10pt
Table Rendering
Tables are fully supported with:- Row and column structure
- Cell borders
- Nested content within cells
- Formatted text in cells
Image Handling
Images are fetched and embedded:CSS Style Support
The encoder parses inline CSS styles:font-weight: Bold textfont-style: Italic texttext-decoration: Underline and strikethroughbackground-color: Background colorcolor: Text colortext-align: Text alignment (left, center, right, justify)
Advanced Features
Todo Lists
Todo lists are rendered with checkboxes:Multi-page Documents
Large documents automatically span multiple pages:Complete Example
Limitations
- Only network images (HTTPS) and local file paths are supported
- Complex CSS layouts are not fully supported
- Font must be explicitly loaded (no system fonts)
- Interactive elements cannot be embedded
- Some advanced markdown features may not render perfectly
Performance Considerations
- Large documents may take time to convert
- Network images are fetched during conversion (blocking)
- Font files increase app size
- Consider showing a loading indicator during export
Troubleshooting
Missing Characters
If characters appear as boxes:- Add appropriate fallback fonts for the language/script
- Ensure font files support the required character set
Image Loading Failures
If images don’t appear:- Verify network connectivity for HTTPS images
- Check file paths for local images
- Ensure proper error handling
Large File Size
To reduce PDF size:- Compress images before export
- Use efficient font subsets
- Consider reducing image resolution
See Also
- Markdown Plugin - Convert to markdown first
- HTML Plugin - Alternative export format
- PDF Package Documentation - PDF library reference