Table of Contents

Class PdfGridCellStyle

Namespace
Syncfusion.Pdf.Grid
Assembly
Syncfusion.Pdf.Portable.dll

Provides customization of the appearance for the PdfGridCell

public class PdfGridCellStyle : PdfGridRowStyle, ICloneable
Inheritance
PdfGridCellStyle
Implements
Inherited Members

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page.
PdfPage page = doc.Pages.Add();
//Create a PdfGrid.
PdfGrid pdfGrid = new PdfGrid();
//Create a DataTable.
DataTable dataTable = new DataTable();
//Add columns to the DataTable
dataTable.Columns.Add("ID");
dataTable.Columns.Add("Name");
//Add rows to the DataTable.
dataTable.Rows.Add(new object[] { "E01", "Clay" });
dataTable.Rows.Add(new object[] { "E02", "Thomas" });
//Assign data source.
pdfGrid.DataSource = dataTable;
//Using the Column collection
pdfGrid.Columns[0].Width = 100;
//Adding grid cell style
PdfGridCellStyle cellStyle = new PdfGridCellStyle();
//Setting text pen for cell
cellStyle.TextBrush = PdfBrushes.Blue;
//Applying style to grid
pdfGrid.Rows[0].Cells[0].Style = cellStyle;
//Draw grid to the page of PDF document.
pdfGrid.Draw(page, new PointF(10, 10));
//Save the document.
doc.Save("Output.pdf");
//close the document
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page.
Dim page As PdfPage = doc.Pages.Add()
'Create a PdfGrid.
Dim pdfGrid As New PdfGrid()
'Create a DataTable.
Dim dataTable As New DataTable()
'Add columns to the DataTable
dataTable.Columns.Add("ID")
dataTable.Columns.Add("Name")
'Add rows to the DataTable.
dataTable.Rows.Add(New Object() {"E01", "Clay"})
dataTable.Rows.Add(New Object() {"E02", "Thomas"})
'Assign data source.
pdfGrid.DataSource = dataTable
'Using the Column collection
pdfGrid.Columns(0).Width = 100
'Adding grid cell style
Dim cellStyle As New PdfGridCellStyle()
'Setting text pen for cell
cellStyle.TextBrush = PdfBrushes.Blue
'Applying style to grid
pdfGrid.Rows(0).Cells(0).Style = cellStyle
'Draw grid to the page of PDF document.
pdfGrid.Draw(page, New PointF(10, 10))
'Save the document.
doc.Save("Output.pdf")
'close the document
doc.Close(True)

Constructors

PdfGridCellStyle()

Initializes a new instance of the PdfGridCellStyle class.

public PdfGridCellStyle()

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page.
PdfPage page = doc.Pages.Add();
//Create a PdfGrid.
PdfGrid pdfGrid = new PdfGrid();
//Create a DataTable.
DataTable dataTable = new DataTable();
//Add columns to the DataTable
dataTable.Columns.Add("ID");
dataTable.Columns.Add("Name");
//Add rows to the DataTable.
dataTable.Rows.Add(new object[] { "E01", "Clay" });
dataTable.Rows.Add(new object[] { "E02", "Thomas" });
//Assign data source.
pdfGrid.DataSource = dataTable;
//Using the Column collection
pdfGrid.Columns[0].Width = 100;
//Adding grid cell style
PdfGridCellStyle cellStyle = new PdfGridCellStyle();
//Create new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
format.Alignment = PdfTextAlignment.Center;
//Set string format to grid cell.
cellStyle.StringFormat = format;
//Set borders.
PdfBorders borders = new PdfBorders();
borders.All = PdfPens.Red;
cellStyle.Borders = borders;
//Set background image.
cellStyle.BackgroundImage = new PdfBitmap("Autumn Leaves.jpg");
//Set cell paddings.
cellStyle.CellPadding = new PdfPaddings(5, 5, 5, 5);
//Applying style to grid
pdfGrid.Rows[0].Cells[0].Style = cellStyle;
//Draw grid to the page of PDF document.
pdfGrid.Draw(page, new PointF(10, 10));
//Save the document.
doc.Save("Output.pdf");
//close the document
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page.
Dim page As PdfPage = doc.Pages.Add()
'Create a PdfGrid.
Dim pdfGrid As New PdfGrid()
'Create a DataTable.
Dim dataTable As New DataTable()
'Add columns to the DataTable
dataTable.Columns.Add("ID")
dataTable.Columns.Add("Name")
'Add rows to the DataTable.
dataTable.Rows.Add(New Object() { "E01", "Clay"})
dataTable.Rows.Add(New Object() { "E02", "Thomas"})
'Assign data source.
pdfGrid.DataSource = dataTable
'Using the Column collection
pdfGrid.Columns(0).Width = 100
'Adding grid cell style
Dim cellStyle As New PdfGridCellStyle()
'Create new PDF string format instance.
Dim format As New PdfStringFormat()
format.Alignment = PdfTextAlignment.Center
'Set string format to grid cell.
cellStyle.StringFormat = format
'Set borders.
Dim borders As New PdfBorders()
borders.All = PdfPens.Red
cellStyle.Borders = borders
'Set background image.
cellStyle.BackgroundImage = New PdfBitmap("Autumn Leaves.jpg")
'Set cell paddings.
cellStyle.CellPadding = New PdfPaddings(5, 5, 5, 5)
'Applying style to grid
pdfGrid.Rows(0).Cells(0).Style = cellStyle
'Draw grid to the page of PDF document.
pdfGrid.Draw(page, New PointF(10, 10))
'Save the document.
doc.Save("Output.pdf")
'close the document
doc.Close(True)

Properties

BackgroundImage

Gets or sets the background image in the PdfGridCell

public PdfImage BackgroundImage { get; set; }

Property Value

PdfImage

The background image.

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page.
PdfPage page = doc.Pages.Add();
//Create a PdfGrid.
PdfGrid pdfGrid = new PdfGrid();
//Create a DataTable.
DataTable dataTable = new DataTable();
//Add columns to the DataTable
dataTable.Columns.Add("ID");
dataTable.Columns.Add("Name");
//Add rows to the DataTable.
dataTable.Rows.Add(new object[] { "E01", "Clay" });
dataTable.Rows.Add(new object[] { "E02", "Thomas" });
//Assign data source.
pdfGrid.DataSource = dataTable;
//Using the Column collection
pdfGrid.Columns[0].Width = 100;
//Adding grid cell style
PdfGridCellStyle cellStyle = new PdfGridCellStyle();
//Create new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
format.Alignment = PdfTextAlignment.Center;
//Set string format to grid cell.
cellStyle.StringFormat = format;
//Set borders.
PdfBorders borders = new PdfBorders();
borders.All = PdfPens.Red;
cellStyle.Borders = borders;
//Set background image.
cellStyle.BackgroundImage = new PdfBitmap("Autumn Leaves.jpg");
//Set cell paddings.
cellStyle.CellPadding = new PdfPaddings(5, 5, 5, 5);
//Applying style to grid
pdfGrid.Rows[0].Cells[0].Style = cellStyle;
//Draw grid to the page of PDF document.
pdfGrid.Draw(page, new PointF(10, 10));
//Save the document.
doc.Save("Output.pdf");
//close the document
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page.
Dim page As PdfPage = doc.Pages.Add()
'Create a PdfGrid.
Dim pdfGrid As New PdfGrid()
'Create a DataTable.
Dim dataTable As New DataTable()
'Add columns to the DataTable
dataTable.Columns.Add("ID")
dataTable.Columns.Add("Name")
'Add rows to the DataTable.
dataTable.Rows.Add(New Object() { "E01", "Clay"})
dataTable.Rows.Add(New Object() { "E02", "Thomas"})
'Assign data source.
pdfGrid.DataSource = dataTable
'Using the Column collection
pdfGrid.Columns(0).Width = 100
'Adding grid cell style
Dim cellStyle As New PdfGridCellStyle()
'Create new PDF string format instance.
Dim format As New PdfStringFormat()
format.Alignment = PdfTextAlignment.Center
'Set string format to grid cell.
cellStyle.StringFormat = format
'Set borders.
Dim borders As New PdfBorders()
borders.All = PdfPens.Red
cellStyle.Borders = borders
'Set background image.
cellStyle.BackgroundImage = New PdfBitmap("Autumn Leaves.jpg")
'Set cell paddings.
cellStyle.CellPadding = New PdfPaddings(5, 5, 5, 5)
'Applying style to grid
pdfGrid.Rows(0).Cells(0).Style = cellStyle
'Draw grid to the page of PDF document.
pdfGrid.Draw(page, New PointF(10, 10))
'Save the document.
doc.Save("Output.pdf")
'close the document
doc.Close(True)

Borders

Gets or sets the border of the PdfGridCell.

public PdfBorders Borders { get; set; }

Property Value

PdfBorders

The border.

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page.
PdfPage page = doc.Pages.Add();
//Create a PdfGrid.
PdfGrid pdfGrid = new PdfGrid();
//Create a DataTable.
DataTable dataTable = new DataTable();
//Add columns to the DataTable
dataTable.Columns.Add("ID");
dataTable.Columns.Add("Name");
//Add rows to the DataTable.
dataTable.Rows.Add(new object[] { "E01", "Clay" });
dataTable.Rows.Add(new object[] { "E02", "Thomas" });
//Assign data source.
pdfGrid.DataSource = dataTable;
//Using the Column collection
pdfGrid.Columns[0].Width = 100;
//Adding grid cell style
PdfGridCellStyle cellStyle = new PdfGridCellStyle();
//Create new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
format.Alignment = PdfTextAlignment.Center;
//Set string format to grid cell.
cellStyle.StringFormat = format;
//Set borders.
PdfBorders borders = new PdfBorders();
borders.All = PdfPens.Red;
cellStyle.Borders = borders;
//Set background image.
cellStyle.BackgroundImage = new PdfBitmap("Autumn Leaves.jpg");
//Set cell paddings.
cellStyle.CellPadding = new PdfPaddings(5, 5, 5, 5);
//Applying style to grid
pdfGrid.Rows[0].Cells[0].Style = cellStyle;
//Draw grid to the page of PDF document.
pdfGrid.Draw(page, new PointF(10, 10));
//Save the document.
doc.Save("Output.pdf");
//close the document
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page.
Dim page As PdfPage = doc.Pages.Add()
'Create a PdfGrid.
Dim pdfGrid As New PdfGrid()
'Create a DataTable.
Dim dataTable As New DataTable()
'Add columns to the DataTable
dataTable.Columns.Add("ID")
dataTable.Columns.Add("Name")
'Add rows to the DataTable.
dataTable.Rows.Add(New Object() { "E01", "Clay"})
dataTable.Rows.Add(New Object() { "E02", "Thomas"})
'Assign data source.
pdfGrid.DataSource = dataTable
'Using the Column collection
pdfGrid.Columns(0).Width = 100
'Adding grid cell style
Dim cellStyle As New PdfGridCellStyle()
'Create new PDF string format instance.
Dim format As New PdfStringFormat()
format.Alignment = PdfTextAlignment.Center
'Set string format to grid cell.
cellStyle.StringFormat = format
'Set borders.
Dim borders As New PdfBorders()
borders.All = PdfPens.Red
cellStyle.Borders = borders
'Set background image.
cellStyle.BackgroundImage = New PdfBitmap("Autumn Leaves.jpg")
'Set cell paddings.
cellStyle.CellPadding = New PdfPaddings(5, 5, 5, 5)
'Applying style to grid
pdfGrid.Rows(0).Cells(0).Style = cellStyle
'Draw grid to the page of PDF document.
pdfGrid.Draw(page, New PointF(10, 10))
'Save the document.
doc.Save("Output.pdf")
'close the document
doc.Close(True)

CellPadding

Gets or sets the cell padding.

public PdfPaddings CellPadding { get; set; }

Property Value

PdfPaddings

The cell padding.

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page.
PdfPage page = doc.Pages.Add();
//Create a PdfGrid.
PdfGrid pdfGrid = new PdfGrid();
//Create a DataTable.
DataTable dataTable = new DataTable();
//Add columns to the DataTable
dataTable.Columns.Add("ID");
dataTable.Columns.Add("Name");
//Add rows to the DataTable.
dataTable.Rows.Add(new object[] { "E01", "Clay" });
dataTable.Rows.Add(new object[] { "E02", "Thomas" });
//Assign data source.
pdfGrid.DataSource = dataTable;
//Using the Column collection
pdfGrid.Columns[0].Width = 100;
//Adding grid cell style
PdfGridCellStyle cellStyle = new PdfGridCellStyle();
//Create new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
format.Alignment = PdfTextAlignment.Center;
//Set string format to grid cell.
cellStyle.StringFormat = format;
//Set borders.
PdfBorders borders = new PdfBorders();
borders.All = PdfPens.Red;
cellStyle.Borders = borders;
//Set background image.
cellStyle.BackgroundImage = new PdfBitmap("Autumn Leaves.jpg");
//Set cell paddings.
cellStyle.CellPadding = new PdfPaddings(5, 5, 5, 5);
//Applying style to grid
pdfGrid.Rows[0].Cells[0].Style = cellStyle;
//Draw grid to the page of PDF document.
pdfGrid.Draw(page, new PointF(10, 10));
//Save the document.
doc.Save("Output.pdf");
//close the document
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page.
Dim page As PdfPage = doc.Pages.Add()
'Create a PdfGrid.
Dim pdfGrid As New PdfGrid()
'Create a DataTable.
Dim dataTable As New DataTable()
'Add columns to the DataTable
dataTable.Columns.Add("ID")
dataTable.Columns.Add("Name")
'Add rows to the DataTable.
dataTable.Rows.Add(New Object() { "E01", "Clay"})
dataTable.Rows.Add(New Object() { "E02", "Thomas"})
'Assign data source.
pdfGrid.DataSource = dataTable
'Using the Column collection
pdfGrid.Columns(0).Width = 100
'Adding grid cell style
Dim cellStyle As New PdfGridCellStyle()
'Create new PDF string format instance.
Dim format As New PdfStringFormat()
format.Alignment = PdfTextAlignment.Center
'Set string format to grid cell.
cellStyle.StringFormat = format
'Set borders.
Dim borders As New PdfBorders()
borders.All = PdfPens.Red
cellStyle.Borders = borders
'Set background image.
cellStyle.BackgroundImage = New PdfBitmap("Autumn Leaves.jpg")
'Set cell paddings.
cellStyle.CellPadding = New PdfPaddings(5, 5, 5, 5)
'Applying style to grid
pdfGrid.Rows(0).Cells(0).Style = cellStyle
'Draw grid to the page of PDF document.
pdfGrid.Draw(page, New PointF(10, 10))
'Save the document.
doc.Save("Output.pdf")
'close the document
doc.Close(True)

StringFormat

Gets the string format of the PdfGridCell.

public PdfStringFormat StringFormat { get; set; }

Property Value

PdfStringFormat

The string format.

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page.
PdfPage page = doc.Pages.Add();
//Create a PdfGrid.
PdfGrid pdfGrid = new PdfGrid();
//Create a DataTable.
DataTable dataTable = new DataTable();
//Add columns to the DataTable
dataTable.Columns.Add("ID");
dataTable.Columns.Add("Name");
//Add rows to the DataTable.
dataTable.Rows.Add(new object[] { "E01", "Clay" });
dataTable.Rows.Add(new object[] { "E02", "Thomas" });
//Assign data source.
pdfGrid.DataSource = dataTable;
//Using the Column collection
pdfGrid.Columns[0].Width = 100;
//Adding grid cell style
PdfGridCellStyle cellStyle = new PdfGridCellStyle();
//Create new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
format.Alignment = PdfTextAlignment.Center;
//Set string format to grid cell.
cellStyle.StringFormat = format;
//Set borders.
PdfBorders borders = new PdfBorders();
borders.All = PdfPens.Red;
cellStyle.Borders = borders;
//Set background image.
cellStyle.BackgroundImage = new PdfBitmap("Autumn Leaves.jpg");
//Set cell paddings.
cellStyle.CellPadding = new PdfPaddings(5, 5, 5, 5);
//Applying style to grid
pdfGrid.Rows[0].Cells[0].Style = cellStyle;
//Draw grid to the page of PDF document.
pdfGrid.Draw(page, new PointF(10, 10));
//Save the document.
doc.Save("Output.pdf");
//close the document
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page.
Dim page As PdfPage = doc.Pages.Add()
'Create a PdfGrid.
Dim pdfGrid As New PdfGrid()
'Create a DataTable.
Dim dataTable As New DataTable()
'Add columns to the DataTable
dataTable.Columns.Add("ID")
dataTable.Columns.Add("Name")
'Add rows to the DataTable.
dataTable.Rows.Add(New Object() { "E01", "Clay"})
dataTable.Rows.Add(New Object() { "E02", "Thomas"})
'Assign data source.
pdfGrid.DataSource = dataTable
'Using the Column collection
pdfGrid.Columns(0).Width = 100
'Adding grid cell style
Dim cellStyle As New PdfGridCellStyle()
'Create new PDF string format instance.
Dim format As New PdfStringFormat()
format.Alignment = PdfTextAlignment.Center
'Set string format to grid cell.
cellStyle.StringFormat = format
'Set borders.
Dim borders As New PdfBorders()
borders.All = PdfPens.Red
cellStyle.Borders = borders
'Set background image.
cellStyle.BackgroundImage = New PdfBitmap("Autumn Leaves.jpg")
'Set cell paddings.
cellStyle.CellPadding = New PdfPaddings(5, 5, 5, 5)
'Applying style to grid
pdfGrid.Rows(0).Cells(0).Style = cellStyle
'Draw grid to the page of PDF document.
pdfGrid.Draw(page, New PointF(10, 10))
'Save the document.
doc.Save("Output.pdf")
'close the document
doc.Close(True)