In the previous page, you learnt to customize the background color of rows of the table by overriding the TableLayout method of the IPdfPTableEvent interface. In this tutorial, you will learn to customize the borders of cells of the table. For example, suppose you want to apply the round rectangle shape to all cells of the table except the cells in the head row as shown below.
To achieve this goal, you need to implement the IPdfPCellEvent interface. The IPdfPCellEvent interface has one method called CellLayout that must be overridden. The CellLayout method has three parameters:
- cell—The PdfPCell object to which the event is added. It is read-only.
- rect—The Rectangle object defining the borders of the cell.
- canvas—An array of PdfContentByte objects that allow you to draw text or add shapes to the cell.
class CustomCell: IPdfPCellEvent
public void CellLayout(PdfPCell cell, Rectangle rect, PdfContentByte canvas)
PdfContentByte cb = canvas[PdfPTable.BACKGROUNDCANVAS];
cb.RoundRectangle(rect.Left, rect.Bottom, rect.Width,rect.Height,3);
Now you have the CustomBorder class that implements the IPdfPCellEvent interface. Next, you need to create an object of CustomBorder class and assign it to the CellEvent property of PdfPCell object. See the example code below.
CustomCell cusborder = new CustomCell();
cellid.CellEvent = cusborder;
You can download the complete C# code of this tutorial from here.
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: