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.
Unfortunately, activation email could not send to your email. Please try again.

Nice table in pdf

Thread ID:

Created:

Updated:

Platform:

Replies:

131167 Jun 26,2017 05:36 AM Jun 29,2017 06:36 AM Windows Forms 5
loading
Tags: PDF
Vhalaky
Asked On June 26, 2017 05:36 AM

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 06:37 AM

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. 


Vhalaky
Replied On June 27, 2017 10:20 AM

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 02:25 AM

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. 


Vhalaky
Replied On June 28, 2017 03:59 AM

Thank you again!


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

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


CONFIRMATION

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.

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.

;