Automatically add new page when it's needed drawing a grid

Hi, I'm drawing a grid using Syncfusion library to manage PDF on Flutter. My problem is that I need to automatically add a new page when the grid reach the end of the document, so it can keep drawing on the new page.

It works only if I manually add a new page, otherwise it truncate the grid data. I want to do it automatically because I'm not sure about the max number of records can be drawn on a page, as row height can be different based on the data.

Actually I'm drawing the grid with

gridCronologia.draw(
                    page: page,
                    bounds: Rect.fromLTWH(0, 30, page.getClientSize().width, page.getClientSize().height - 80),
                    format: PdfLayoutFormat(
                      breakType: PdfLayoutBreakType.fitPage,
                      layoutType: PdfLayoutType.paginate,
                    ));



Thanks


1 Reply

IJ Irfana Jaffer Sadhik Syncfusion Team June 16, 2023 11:02 AM UTC

Please use the below code for paginating PDF grid:

//Create a new PDF documentation

  PdfDocument document = PdfDocument();

//Create a PdfGrid

  PdfGrid grid = PdfGrid();

//Add the columns to the grid

  grid.columns.add(count: 3);

  grid.headers.add(1);

  PdfGridRow header = grid.headers[0];

  header.cells[0].value = 'Column 1';

  header.cells[1].value = 'Column 2';

  header.cells[2].value = 'Column 3';

  for (int i = 0; i < 100; i++) {

//Add rows to grid. Set the cells style

    PdfGridRow row1 = grid.rows.add();

    row1.cells[0].value = 'Row ${i + 1}_1';

    row1.cells[1].value = 'Row ${i + 1}_2';

    row1.cells[2].value = 'Row ${i + 1}_3';

  }

//Create a PdfLayoutFormat for pagination

  PdfLayoutFormat format = PdfLayoutFormat(

      breakType: PdfLayoutBreakType.fitColumnsToPage,

      layoutType: PdfLayoutType.paginate);

//Draw the grid in PDF document page

  grid.draw(

      page: document.pages.add(),

      bounds: const Rect.fromLTWH(0, 0, 0, 0),

      format: format);



Follow the below link for 


Loader.
Up arrow icon