generate static method

Future<File> generate(
  1. Invoice invoice
)

Generates a PDF invoice file from the provided invoice data.

The generated PDF is saved in the temporary directory with a filename based on the invoice number.

Returns a File object pointing to the generated PDF.

Implementation

static Future<File> generate(Invoice invoice) async {
  final pdf = pw.Document();

  pdf.addPage(pw.MultiPage(
    build: (context) => [
      _buildHeader(invoice),
      pw.SizedBox(height: 3 * PdfPageFormat.cm),
      _buildTitle(invoice),
      _buildInvoice(invoice),
      pw.Divider(),
      _buildTotal(invoice),
    ],
    footer: (context) => _buildFooter(invoice),
  ));

  final outputDir = await getTemporaryDirectory();
  final file = File(p.join(outputDir.path, 'invoice_${invoice.info.number}.pdf'));
  await file.writeAsBytes(await pdf.save());
  return file;
}