Make you changes like below while building your
htmlviaStringBuilderlikeStringBuilder sb = new StringBuilder();
//Open table sb.Append("");
//Open first tr for all of th sb.Append(""); foreach (DataColumn column in dt.Columns) { sb.Append(""); sb.Append(column.ColumnName); sb.Append(""); }
//Close first tr for all of th sb.Append("");
foreach (DataRow row in dt.Rows) {
//Open tr for all of rows sb.Append(""); foreach (DataColumn column in dt.Columns) { sb.Append(""); sb.Append(row[column]); sb.Append(""); }//Close tr for all of rows sb.Append("</tr>");}
//Close table sb.Append("");
Use
XMLWorkerHelperinstead ofHTMLWorkerbecause nowHTMLWorkeris deprecated. and not more support byiTextSharp. likePdfWriter writer = PdfWriter.GetInstance(pdfDoc, memoryStream); pdfDoc.Open(); XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr); pdfDoc.Close(); byte[] bytes = memoryStream.ToArray(); memoryStream.Close();
See this link
Try once may it help you.