flutter_pdf_export 1.0.0 copy "flutter_pdf_export: ^1.0.0" to clipboard
flutter_pdf_export: ^1.0.0 copied to clipboard

A Flutter package for generating beautifully styled PDFs with automatic multi-script font resolution. Supports Arabic, Hebrew, CJK, Devanagari, and 15+ other scripts out of the box. Returns a File you [...]

Features #

  • ๐ŸŒ 21 scripts supported โ€” Arabic, Urdu, Hebrew, Hindi, Bengali, Gujarati, Tamil, Telugu, Kannada, Malayalam, Sinhala, Thai, Lao, Myanmar, Khmer, Ethiopic, Georgian, Armenian, Korean, Chinese, Latin
  • ๐Ÿ”ค Font auto-detection โ€” resolved per paragraph, not per document
  • โ†”๏ธ RTL auto-detection โ€” Arabic and Hebrew paragraphs are right-aligned automatically
  • ๐Ÿ–ผ Image embedding โ€” PNG / JPEG bytes with caption, width fraction, and alignment control
  • **bold** inline formatting โ€” works in paragraphs and bullets
  • ๐Ÿ“ Markdown parser โ€” # H1, ## H2, **bold**, - bullets, --- dividers
  • ๐ŸŽจ Fully customisable style โ€” colors, font sizes, margins, header bar, footer text, page format
  • ๐Ÿ“ฆ 4 preset styles โ€” PdfStyle.light, .dark, .minimal, .warm
  • ๐Ÿ’พ Disk font cache โ€” downloaded once, persisted between sessions
  • ๐Ÿ“„ Returns dart:io File โ€” integrate with share_plus, open_file, file_saver, or any package

Installation #

Add to your pubspec.yaml:

dependencies:
  flutter_pdf_export: ^1.0.0

Then run:

flutter pub get

Quick Start #

From Markdown #

import 'package:flutter_pdf_export/flutter_pdf_export.dart';

final file = await PdfBuilder.generate(
  PdfDocumentData.fromMarkdown(
    title: 'My Report',
    markdown: '''
# Introduction
This is **bold** and this is normal.

## Arabic
ู‡ุฐุง ู†ุต ุนุฑุจูŠ โ€” font and RTL detected automatically.

- Bullet one
- Bullet two
  - Nested bullet
''',
  ),
);

// file is a dart:io File โ€” do what you want with it:
// share_plus  โ†’ Share.shareXFiles([XFile(file.path)])
// open_file   โ†’ OpenFile.open(file.path)
// file_saver  โ†’ FileSaver.instance.saveFile(...)

From Structured Sections #

final file = await PdfBuilder.generate(
  PdfDocumentData(
    title: 'My Document',
    author: 'My App',
    style: PdfStyle.light.copyWith(
      footerLeftText: 'My App',
      showPageNumbers: true,
    ),
    sections: [
      // Image โ€” PNG/JPEG bytes from File, image_picker, or assets
      PdfSection.image(
        imageBytes,
        caption: 'Figure 1 โ€” Sample image',
        widthFraction: 0.9,   // 90% of page width
        alignment: 'center',  // 'left' | 'center' | 'right'
      ),

      PdfSection.h1('Hello, PDF!'),
      PdfSection.h2('Sub Heading'),
      PdfSection.paragraph('Regular text with **bold** inline.'),

      // Arabic โ€” RTL detected automatically, no config needed
      PdfSection.paragraph('ู‡ุฐุง ู†ุต ุนุฑุจูŠ. ูŠุชู… ุงูƒุชุดุงู ุงู„ุฎุท ุชู„ู‚ุงุฆูŠู‹ุง.'),

      PdfSection.bullet('First bullet'),
      PdfSection.bullet('Second bullet'),
      PdfSection.bullet('Nested', level: 1),

      PdfSection.divider(),
      PdfSection.paragraph('Done.'),
    ],
  ),
);

Providing Image Bytes #

// From flutter assets
final data = await rootBundle.load('assets/my_image.png');
final bytes = data.buffer.asUint8List();

// From a dart:io File (e.g. file_picker, image_picker)
final bytes = await File('/path/to/image.jpg').readAsBytes();

// From image_picker
final xfile = await ImagePicker().pickImage(source: ImageSource.gallery);
final bytes = await xfile!.readAsBytes();

Styles #

Use a preset #

style: PdfStyle.dark     // charcoal background, white text
style: PdfStyle.light    // clean white, blue accent
style: PdfStyle.minimal  // no bar, wide margins
style: PdfStyle.warm     // parchment background

Customise with copyWith #

style: PdfStyle.light.copyWith(
  accentColor: const PdfColor.fromInt(0xFF6200EE),
  footerLeftText: 'My App',
  showHeaderBar: true,
  showPageNumbers: true,
  bodyFontSize: 14,
  horizontalMargin: 56,
),

Build from scratch #

style: const PdfStyle(
  pageFormat: PdfPageFormat.letter,
  accentColor: PdfColor.fromInt(0xFF1565C0),
  textColor: PdfColor.fromInt(0xFF212121),
  backgroundColor: PdfColors.white,
  h1FontSize: 26,
  h2FontSize: 20,
  bodyFontSize: 13,
  bodyLineHeight: 1.8,
  showHeaderBar: true,
  headerBarHeight: 5,
  footerLeftText: 'Company Name',
  showPageNumbers: true,
  horizontalMargin: 48,
  verticalMargin: 52,
),

PdfSection Reference #

Factory Description
PdfSection.h1(text) H1 heading โ€” accent color
PdfSection.h2(text) H2 heading โ€” body color
PdfSection.h3(text) H3 heading โ€” subtitle color
PdfSection.heading(text) Alias for h2
PdfSection.paragraph(text) Body text, supports **bold**
PdfSection.bullet(text, level: 0) Bullet item, level = nesting depth
PdfSection.image(bytes, caption, widthFraction, alignment) Embedded image
PdfSection.divider() Horizontal rule
PdfSection.spacer() Vertical whitespace
PdfSection.markdown(text) Raw markdown, parsed automatically

PdfStyle Properties #

Property Type Default Description
pageFormat PdfPageFormat A4 Page size
horizontalMargin double 48 Left/right margin in points
verticalMargin double 52 Top/bottom margin in points
accentColor PdfColor Pink H1 heading + header bar color
textColor PdfColor Near-black Body text and H2 color
subtitleColor PdfColor Grey H3 and caption color
backgroundColor PdfColor White Page background
h1FontSize double 22 H1 font size in points
h2FontSize double 20 H2 font size in points
h3FontSize double 16 H3 font size in points
bodyFontSize double 13 Paragraph and bullet font size
bodyLineHeight double 1.6 Line height multiplier
showHeaderBar bool true Accent bar at top of each page
headerBarHeight double 4 Bar height in points
showHeaderTitle bool false Show document title in header
showPageNumbers bool true Page N / Total in footer
footerLeftText String? null Left footer text (e.g. app name)
bulletIndentPerLevel double 12 Points of indent per nesting level

Supported Scripts #

Script Font Used
Latin, Cyrillic Noto Sans
Arabic, Urdu, Persian Noto Naskh Arabic
Hebrew Noto Sans Hebrew
Hindi / Marathi (Devanagari) Noto Sans Devanagari
Bengali Noto Sans Bengali
Punjabi (Gurmukhi) Noto Sans Gurmukhi
Gujarati Noto Sans Gujarati
Tamil Noto Sans Tamil
Telugu Noto Sans Telugu
Kannada Noto Sans Kannada
Malayalam Noto Sans Malayalam
Sinhala Noto Sans Sinhala
Thai Noto Sans Thai
Lao Noto Sans Lao
Myanmar Noto Sans Myanmar
Khmer Noto Sans Khmer
Ethiopic Noto Sans Ethiopic
Georgian Noto Sans Georgian
Armenian Noto Sans Armenian
Korean Noto Sans KR
Chinese (Simplified) Noto Sans SC

Fonts are downloaded from Google Fonts on first use, then cached to disk permanently.


Advanced: FontResolver #

// Detect which font family a string needs
final family = FontResolver.familyFor('ู…ุฑุญุจุง'); // 'Noto+Naskh+Arabic'

// Pre-warm the cache before building a PDF (parallel downloads)
await FontResolver.preload(['Hello', 'ู…ุฑุญุจุง', 'ใ“ใ‚“ใซใกใฏ']);

// Resolve a font directly (useful for custom pw.Document builds)
final font = await FontResolver.resolveFamily('Noto+Sans+Devanagari', bold: true);

Showing a Preview #

Use the printing package's PdfPreview widget (already a transitive dependency):

import 'package:printing/printing.dart';

Navigator.push(context, MaterialPageRoute(
  builder: (_) => Scaffold(
    appBar: AppBar(title: const Text('Preview')),
    body: PdfPreview(
      build: (format) => file.readAsBytes(),
      pdfFileName: 'my_document.pdf',
    ),
  ),
));

Dependencies #

Package Version Purpose
pdf ^3.10.8 PDF generation engine
printing ^5.13.1 Google Fonts download + PdfPreview
path_provider ^2.1.3 Disk font cache directory

License #

MIT ยฉ 2025 โ€” see LICENSE

Developed by ABOU BAKAR - ab.dev.pk@gmail.com #

2
likes
0
points
44
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for generating beautifully styled PDFs with automatic multi-script font resolution. Supports Arabic, Hebrew, CJK, Devanagari, and 15+ other scripts out of the box. Returns a File you can save, share, or open with any picker.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, path_provider, pdf, printing

More

Packages that depend on flutter_pdf_export