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 add formatted html into a PdfLightTableCell?

Platform: WinForms |
Control: PDF |
Published Date: February 4, 2015 |
Last Revised Date: May 7, 2019
Tags: pdf, html, table

How to add formatted HTML into a PdfLightTableCell?

You can use PdfHTMLTextElement to add the formatted HTML tags in PdfLightTable.

The HTML text cannot be added directly. However, this can be done using the BeginCellLayout event handler.

Please refer to the following code example how to draw the HTML element into the PdfLightTableCell:

C#

//create the document
PdfDocument document = new PdfDocument();
 
//Add the page
PdfPage page = document.Pages.Add();
 
//Create the table
PdfLightTable table = new PdfLightTable();
 
//Load the data
table.DataSource = DataTable();
 
//Handle the row events
table.BeginRowLayout += table_BeginRowLayout;
 
//Handle the cell events
table.BeginCellLayout += table_BeginCellLayout;
 
//Draw the table
table.Draw(page, new PointF(0, 20));
 
// Save and close the document.
document.Save("Sample.pdf");
document.Close(true);
 
private DataTable DataTable()
{
//Create a data table.
DataTable table = new DataTable();
 
for (int i = 0; i < 5; i++)
table.Columns.Add();
 
table.Rows.Add(new object[] { " ", "Cell2", "cell 3" });
table.Rows.Add(new object[] { " ", "Cell2", "cell 3" });
table.Rows.Add(new object[] { " ", "Cell2", "cell 3" });
table.Rows.Add(new object[] { " ", "Cell2", "cell 3" });
table.Rows.Add(new object[] { " ", "Cell2", "cell 3" });
table.Rows.Add(new object[] { " ", "Cell2", "cell 3" });
 
return table;
}
 
private void table_BeginCellLayout(object sender, BeginCellLayoutEventArgs args)
{
// Create the PdfTextElement
PdfHTMLTextElement textElement = new PdfHTMLTextElement();
textElement.HTMLText = "<html> <head>Html </head><body><i> Formatted Text</i></body></html>";
textElement.Font = new PdfStandardFont(PdfFontFamily.Courier, 10);
 
//Draw the Html Element in first cells
if (args.CellIndex == 0)
textElement.Draw(args.Graphics, args.Bounds);
}
 
private void table_BeginRowLayout(object sender, BeginRowLayoutEventArgs args)
{
//Set the height of the row
args.MinimalHeight = 30;
}

 

Sample link:

http://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfLightTableSample1029052034.zip

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Matthew Smith
Jul 06, 2015
Why doesn't the documentation reflect this? If the Value property cannot accept a particular object, it should state it in the documentation. Reply
KarthikeyanC [Syncfusion]
Jul 06, 2015
Hi Matthew, Thank you for your feedback, We will update our documentation with these details. Regards, Karthikeyan.C Reply

Please sign in to access our KB

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