We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to format cells in a PDF Table?

Platform: WinForms |
Control: PDF |
Published Date: April 30, 2011 |
Last Revised Date: May 7, 2019
Tags: pdf, pdfgrid

Format cells in PDF table

All the cells in a PDF Grid have a style object associated with it. The properties of the style object can be set as shown in the code snippet below.

C#

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
 
//Add a page.
PdfPage page = doc.Pages.Add();
 
//Acquire page's graphics.
PdfGraphics graphics = page.Graphics;
 
//Create a PdfGrid.
PdfGrid table = 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" });
dataTable.Rows.Add(new object[] { "E03", "George" });
 
//Assign data source.
table.DataSource = dataTable;
 
// To set the backcolor.
table.Rows[1].Cells[1].Style.BackgroundBrush= Color.Red;
 
//Alignment of the text inside the cell.
table.Rows[1].Cells[0].Style.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 8f);
table.Rows[1].Cells[1].Style.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
table.Rows[1].Cells[2].Style.StringFormat = new PdfStringFormat(PdfTextAlignment.Right);
table.Rows[1].Cells[0].Style.StringFormat = new PdfStringFormat(PdfTextAlignment.Left);
table.Draw(page, new PointF(10, 10));
 
//Save the document.
 doc.Save("Output.pdf");
 
//close the document.
doc.Close(true);

Sample link:

http://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfGridStyle-1517197644

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Ewen Wallace
Jan 09, 2017
"This will work only with PDF.Legacy.Base" - so what works now? Reply
Gayathri Ramalingam [Syncfusion]
Jan 11, 2017
Hi Ewen,
Thank you for your feedback, we have refreshed this KB content to support for the new Syncfusion.Pdf.Base.

Regards,
Gayathri R
Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon