DavBfr / dart_pdf

Pdf creation module for dart/flutter
https://pub.dev/packages/pdf
Apache License 2.0
1.36k stars 593 forks source link

How to split a widget such that it spans across multiple pages. #1680

Open aditya113141 opened 2 weeks ago

aditya113141 commented 2 weeks ago

I am using a Table Widget and some cells have huge text such that they make their corresponding row bigger than the page height and need to move to next page partially.

class PdfService {
  Future<Uint8List> generatePdf(List<Map<String, dynamic>> tableData) async {
    final pdf = pw.Document();

    // Define column widths
    final columnWidths = {
      0: const pw.FixedColumnWidth(100),
      1: const pw.FixedColumnWidth(5),
      2: const pw.FixedColumnWidth(100), // Adjust as needed
    };

    // Create a table with dynamic data
    final table = pw.Table.fromTextArray(
      columnWidths: columnWidths,
      data: tableData.map((row) => row.values.toList()).toList(),
      border: pw.TableBorder.all(),
      cellAlignment: pw.Alignment.centerLeft,
      headerStyle: pw.TextStyle(fontSize: 10, fontWeight: pw.FontWeight.bold),
      cellStyle: pw.TextStyle(fontSize: 10),
    );

    pdf.addPage(
      pw.MultiPage(
        orientation: pw.PageOrientation.landscape,
        build: (context) => [
          table,
        ],
        header: (context) => pw.Text('Dynamic Table Example'),
        footer: (context) =>
            pw.Text('Page ${context.pageNumber} of ${context.pagesCount}'),
      ),
    );

    return await pdf.save();
  }
}
himanshu447 commented 1 week ago

is there any update regarding this issue @aditya113141

aditya113141 commented 6 days ago

Not on our side.