style property

PdfGridCellStyle get style

Gets or sets the cell style.

//Create a new PDF document
PdfDocument document = PdfDocument();
//Create a PdfGrid
PdfGrid grid = PdfGrid();
//Add columns to grid
grid.columns.add(count: 3);
//Add headers to grid
PdfGridRow header = grid.headers.add(1)[0];
header.cells[0].value = 'Employee ID';
header.cells[1].value = 'Employee Name';
header.cells[2].value = 'Salary';
//Add the styles to specific cell
header.cells[0].style.stringFormat = PdfStringFormat(
    alignment: PdfTextAlignment.center,
    lineAlignment: PdfVerticalAlignment.bottom,
    wordSpacing: 10);
header.cells[1].style.textPen = PdfPens.mediumVioletRed;
header.cells[2].style.backgroundBrush = PdfBrushes.yellow;
header.cells[2].style.textBrush = PdfBrushes.darkOrange;
//Add rows to grid
PdfGridRow row1 = grid.rows.add();
row1.cells[0].value = 'E01';
row1.cells[1].value = 'Clay';
//Apply the cell style to specific row cells
row1.cells[0].style = PdfGridCellStyle(
  backgroundBrush: PdfBrushes.lightYellow,
  cellPadding: PdfPaddings(left: 2, right: 3, top: 4, bottom: 5),
  font: PdfStandardFont(PdfFontFamily.timesRoman, 17),
  textBrush: PdfBrushes.white,
  textPen: PdfPens.orange,
);
PdfGridCell gridCell = PdfGridCell(
    row: row1,
    format: PdfStringFormat(
        alignment: PdfTextAlignment.center,
        lineAlignment: PdfVerticalAlignment.bottom,
        wordSpacing: 10));
gridCell.value = '\$10,000';
row1.cells[2].value = gridCell.value;
row1.cells[2].stringFormat = gridCell.stringFormat;
PdfGridRow row2 = grid.rows.add();
row2.cells[0].value = 'E02';
row2.cells[1].value = 'Simon';
row2.cells[2].value = '\$12,000';
//Add the style to specific cell
row2.cells[2].style.borders = PdfBorders(
    left: PdfPen(PdfColor(240, 0, 0), width: 2),
    top: PdfPen(PdfColor(0, 240, 0), width: 3),
    bottom: PdfPen(PdfColor(0, 0, 240), width: 4),
    right: PdfPen(PdfColor(240, 100, 240), width: 5));
//Draw the grid in PDF document page
grid.draw(
    page: document.pages.add(), bounds: Rect.zero);
//Save the document.
List<int> bytes = await document.save();
//Dispose the document.
document.dispose();

Implementation

PdfGridCellStyle get style {
  _style ??= PdfGridCellStyle();
  return _style!;
}
set style (PdfGridCellStyle value)

Implementation

set style(PdfGridCellStyle value) {
  _style = value;
}