2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
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.
This page will automatically be redirected to the sign-in page in 10 seconds.