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();
}
}
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.