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

Nice table in pdf

Thread ID:





131167 Jun 26,2017 09:36 AM UTC Jun 29,2017 10:36 AM UTC WinForms 5
Tags: PDF
Asked On June 26, 2017 09:36 AM UTC

Hello, we have a table in a pdf but it is rather ugly.

How can we format properly? Can you provide a small sample?

We would like: inner margin (padding) in cells, center vertical, border color, alternate row color, header. Like on attached image.

Attachment: table_842f80f.zip

Sasi Kumar Sekar [Syncfusion]
Replied On June 27, 2017 10:37 AM UTC

Hi Mate, 
Thank you for contacting Syncfusion support, 
We can customize the PdfLightTable by using Style property. We have created the simple sample to achieve your query. Please find the below code snippet and sample for your reference. 
Code snippet: 
//Creates a new PDF document. 
PdfDocument doc = new PdfDocument(); 
//Adds a page. 
PdfPage page = doc.Pages.Add(); 
//Declares a PdfLightTable. 
PdfLightTable pdfLightTable = new PdfLightTable(); 
//Sets the DataSourceType as Direct. 
pdfLightTable.DataSourceType = PdfLightTableDataSourceType.TableDirect; 
//Creates columns. 
pdfLightTable.Columns.Add(new PdfColumn("Company")); 
pdfLightTable.Columns.Add(new PdfColumn("Contact")); 
pdfLightTable.Columns.Add(new PdfColumn("Country")); 
//Adds rows. 
pdfLightTable.Rows.Add(new object[] { "111", "Maxim", "III" }); 
pdfLightTable.Rows.Add(new object[] { "222", "Bell", "III" }); 
pdfLightTable.Rows.Add(new object[] { "333", "cell", "III" }); 
pdfLightTable.Rows.Add(new object[] { "444", "Gell", "III" }); 
pdfLightTable.Rows.Add(new object[] { "555", "kelvin", "III" }); 
PdfCellStyle alternatestyle = new PdfCellStyle(); 
alternatestyle.BackgroundBrush = PdfBrushes.LightBlue; 
alternatestyle.BorderPen = new PdfPen(Color.DarkViolet, 1f); 
//Set style to alternate row 
pdfLightTable.Style.AlternateStyle = alternatestyle; 
PdfCellStyle defaultstyle = new PdfCellStyle(); 
defaultstyle.BorderPen = new PdfPen(Color.DarkViolet, 1f); 
pdfLightTable.Style.DefaultStyle = defaultstyle; 
PdfCellStyle headerstyle = new PdfCellStyle(); 
headerstyle.BackgroundBrush = PdfBrushes.Green; 
//Set style to header. 
pdfLightTable.Style.HeaderStyle = headerstyle; 
//Create a new string format 
PdfStringFormat format = new PdfStringFormat(); 
//Set the text Alignment 
format.Alignment = PdfTextAlignment.Left; 
//Set the line Alignment 
format.LineAlignment = PdfVerticalAlignment.Middle; 
//Set Stringformat to the lightTable cells. 
for (int i = 0; i < 3; i++) 
pdfLightTable.Columns[i].StringFormat = format; 
//Show the header of lighttable. 
pdfLightTable.Style.ShowHeader = true; 
//Set padding to the cells. 
pdfLightTable.Style.CellPadding = 2f; 
//Draw the light table. 
pdfLightTable.Draw(page, PointF.Empty); 
Please let us know if you need further assistance on this. 
Sasi Kumar S. 

Replied On June 27, 2017 02:20 PM UTC

Perfect, thanks!

I have an another problem with hungarian accented characters. Eg. ő will be õ.

Can I ask here or do I have to create a new topic?

Sasi Kumar Sekar [Syncfusion]
Replied On June 28, 2017 06:25 AM UTC

Hi Mate, 
By default the standard font is used to draw the text in PdfLightTable, but the standard font do not support all Unicode characters. So, we suggest to use PdfTrueTypeFont as the default style font for the PdfLightTable to preserve Unicode character like the Hungarian character ‘ő’. 
Please refer to the below code snippet to create the PdfTrueTypeFont and assign it to the PdfLightTable default Style. 
PdfCellStyle defaultstyle = new PdfCellStyle(); 
//Create the PdfTrueTypeFont. 
PdfFont font= new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Regular), true); 
//Assign the font to the cellstyle. 
defaultstyle.Font = font; 
pdfLightTable.Style.DefaultStyle = defaultstyle;  
Please let us know if you need further assistance. 
Sasi Kumar S. 

Replied On June 28, 2017 07:59 AM UTC

Thank you again!

Sasi Kumar Sekar [Syncfusion]
Replied On June 29, 2017 10:36 AM UTC

Hi Mate, 
Thank you for your update, 
 Please let us know if you need further assistance in this. 
Sasi Kumar S. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

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

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