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. Image for the cookie policy date

Nice table in pdf

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

5 Replies

SK Sasi Kumar Sekar Syncfusion Team 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); 
 
doc.Save("output.pdf"); 
doc.Close(true); 
 
 
Sample: 
Please let us know if you need further assistance on this. 
Regards, 
Sasi Kumar S. 



VH Vhalaky 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?



SK Sasi Kumar Sekar Syncfusion Team 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. 
 
Thanks, 
Sasi Kumar S. 



VH Vhalaky June 28, 2017 07:59 AM UTC

Thank you again!



SK Sasi Kumar Sekar Syncfusion Team 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. 
Regards, 
Sasi Kumar S. 


Loader.
Live Chat Icon For mobile
Up arrow icon