DavBfr / dart_pdf

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

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

Open aditya113141 opened 5 months ago

aditya113141 commented 5 months 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 5 months ago

is there any update regarding this issue @aditya113141

aditya113141 commented 5 months ago

Not on our side.

MichelMelhem commented 4 months ago

up

CatHood0 commented 3 months ago

Can i see how is displaying the table on the PDF in a image? I guess this could be an issue from FixedColumnWidth that couldn't be spanning (weird, since Table widget is a SpanningWidget that makes possible breaks the Table at certain part and persist the Table to the next page)