generateFromMarkdown static method

Future<Uint8List> generateFromMarkdown({
  1. required String content,
  2. String title = 'Documento',
  3. DocTheme theme = DocTheme.standard,
})

Generate a PDF from markdown-like content.

Returns the raw PDF bytes ready for download. title is used as the document metadata title. content is the markdown-like text to render. theme allows customizing colors and branding.

Implementation

static Future<Uint8List> generateFromMarkdown({
  required String content,
  String title = 'Documento',
  DocTheme theme = DocTheme.standard,
}) async {
  await _ensureFonts();

  final pdf = pw.Document(
    theme: pw.ThemeData.withFont(
      base: _regular,
      bold: _bold,
      italic: _light,
    ),
  );

  final bodyWidgets = _parseMarkdownToWidgets(content, theme);
  final dateStr = _formatDate(DateTime.now());

  pdf.addPage(
    pw.MultiPage(
      pageFormat: PdfPageFormat.letter,
      margin: const pw.EdgeInsets.only(
        left: 50, right: 50, top: 30, bottom: 40,
      ),
      header: (context) => _buildHeader(title, dateStr, context, theme),
      footer: (context) => _buildFooter(context, theme),
      build: (context) => bodyWidgets,
    ),
  );

  return pdf.save();
}