quick_html_pdf library

QuickHtmlPdf - Fast HTML to PDF conversion for Flutter Web.

A high-performance Flutter Web package that converts HTML templates with dynamic data into PDFs using JavaScript interoperability.

Features

  • Fast download mode: Uses native browser print for instant PDF generation
  • Bytes mode: Returns PDF as Uint8List for further processing
  • Template engine: Support for {{placeholders}}, loops, and raw HTML
  • Print CSS: Optimized CSS for accurate pagination
  • Large documents: Chunked rendering for 200+ page documents

Quick Start

import 'package:quick_html_pdf/quick_html_pdf.dart';

// Generate PDF and trigger download
await QuickHtmlPdf.generate(
  htmlTemplate: '<h1>Hello {{name}}</h1>',
  data: {'name': 'World'},
  options: PdfOptions(output: PdfOutput.download),
);

// Generate PDF and get bytes
final bytes = await QuickHtmlPdf.generate(
  htmlTemplate: '<h1>Hello {{name}}</h1>',
  data: {'name': 'World'},
  options: PdfOptions(output: PdfOutput.bytes),
);

Template Syntax

  • {{key}} - HTML-escaped interpolation
  • {{nested.path}} - Dot notation for nested objects
  • {{{rawHtml}}} - Unescaped HTML insertion
  • {{#each items}}...{{/each}} - Loop blocks
  • {{this.field}} - Access current item in loop
  • {{@index}} - Current loop index (0-based)

Platform Support

This package is web-only. It throws UnsupportedError on mobile and desktop platforms.

Classes

HtmlComposer
Composes a complete HTML document with print CSS.
PdfMargins
Margins for PDF pages in millimeters.
PdfOptions
Configuration options for PDF generation.
QuickHtmlPdf
QuickHtmlPdf - Fast HTML to PDF conversion for Flutter Web.
TemplateEngine
Template engine that processes HTML templates with dynamic data.

Enums

PdfGenerationPhase
Phases of PDF generation where errors can occur.
PdfOrientation
Page orientation for the PDF.
PdfOutput
Output mode for PDF generation.
PdfPageFormat
Page format for the PDF.

Exceptions / Errors

PdfGenerationException
Exception thrown when PDF generation fails.
TemplateException
Exception thrown when template parsing or rendering fails.