Hello Sir,
I'm trying to export html table to pdf. Below is the code i am using.
The width for this remaining same for all.
How to set width for th from code behind.
Document pdfDoc = new Document();
PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream);
pdfDoc.Open();
string strHTML = @"<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title></title>
</head>
<body>
<div align = 'center'><h3><b>This is my header</b></h3></div>
<table border = '1' width=100%>
<tr>
<th style = 'background-color: #249ABB;color:#ffffff;width=1%'>No</th>
<th style = 'background-color: #249ABB;color:#ffffff;width=1%'>Name</th>
<th style = 'background-color: #249ABB;color:#ffffff;width=1%'>Sem</th>
<th style = 'background-color: #249ABB;color:#ffffff;width=84%'>Subjects</th>
<th style = 'background-color: #249ABB;color:#ffffff;width=1%'>DOB</th>
<th style = 'background-color: #249ABB;color:#ffffff;width=1%'>Mobile No</th>
<th style = 'background-color: #249ABB;color:#ffffff;width=11%'>Address</th>
</tr>
<tr>
<td>1</td>
<td>ABC</td>
<td>2</td>
<td>CCp,DBMS,Operating system,FAFL,Logic Design</td>
<td>12/12/1996</td>
<td>9900778866</td>
<td>Test Test</td>
</tr>
</table>
</body>
</html>";
HTMLWorker htmlWorker = new HTMLWorker(pdfDoc);
htmlWorker.Parse(new StringReader(strHTML));
pdfWriter.CloseStream = false;
pdfDoc.Close();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Test.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.Flush();
Response.End();
Thanks