draw method

  1. @override
PdfLayoutResult? draw({
  1. Rect? bounds,
  2. PdfLayoutFormat? format,
  3. PdfGraphics? graphics,
  4. PdfPage? page,
})
override

Draws the PdfGrid

//Create a new PDF document
PdfDocument document = PdfDocument();
//Create a PdfGrid class
PdfGrid grid = PdfGrid();
//Add the columns to the grid
grid.columns.add(count: 3);
//Add header to the grid
grid.headers.add(1);
//Add the rows to the grid
PdfGridRow header = grid.headers[0];
header.cells[0].value = 'Employee ID';
header.cells[1].value = 'Employee Name';
header.cells[2].value = 'Salary';
//Add rows to grid
PdfGridRow row = grid.rows.add();
row.cells[0].value = 'E01';
row.cells[1].value = 'Clay';
row.cells[2].value = '\$10,000';
row = grid.rows.add();
row.cells[0].value = 'E02';
row.cells[1].value = 'Simon';
row.cells[2].value = '\$12,000';
//Draw the grid
grid.draw(
    page: document.pages.add(), bounds: Rect.zero);
//Save the document.
List<int> bytes = await document.save();
//Dispose the document.
document.dispose();

Implementation

@override
PdfLayoutResult? draw(
    {Rect? bounds,
    PdfLayoutFormat? format,
    PdfGraphics? graphics,
    PdfPage? page}) {
  final PdfRectangle rectangle =
      bounds != null ? PdfRectangle.fromRect(bounds) : PdfRectangle.empty;
  _helper.initialWidth = rectangle.width == 0
      ? page != null
          ? page.getClientSize().width
          : graphics!.clientSize.width
      : rectangle.width;
  _helper.isWidthSet = true;
  if (page != null) {
    final PdfLayoutResult? result =
        super.draw(page: page, bounds: bounds, format: format);
    _helper.isComplete = true;
    return result;
  } else if (graphics != null) {
    _helper.drawInternal(graphics, rectangle);
  }
  return null;
}