I am using Itextsharp.dll to convert html table to pdf. Pls find below my code.
aspx:
<asp:Panel ID="PnlTable" runat="server" ScrollBars="Horizontal" Width="707px" Visible="false">
<asp:Table ID="tbDynamic" CellPadding="2" CellSpacing="2" Width="100%" runat="server">
</asp:Table>
</asp:Panel>
<asp:Button ID="btnExport" runat="server" Text="Export" OnClick="btnExport_Click" />
cs :
protected void btnExport_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
Label lb = new Label();
Table dt = new Table();
TableRow trow = new TableRow();
TableCell tcell = new TableCell();
LiteralControl l1 = new LiteralControl();
PnlTable.Visible = true;
sb.Append("<table style='width:100%;text-align:center' border='1'>");
sb.Append("<tr>");
sb.Append("<td>Index</td>");
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td>");
sb.Append("<table style='width:100%;' border='0'>");
sb.Append("<tr>");
sb.Append("<td>First</td>");
sb.Append("<td>Second</td>");
sb.Append("<td>Third</td>");
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td>Fourth</td>");
sb.Append("<td>Fifth</td>");
sb.Append("<td>Six</td>");
sb.Append("<tr>");
sb.Append("<tr>");
sb.Append("<td>Seven</td>");
sb.Append("<td>Eight</td>");
sb.Append("<td>Nine</td>");
sb.Append("</tr>");
sb.Append("</table>");
sb.Append("</td>");
sb.Append("</tr>");
sb.Append("</table>");
l1 = new LiteralControl(sb.ToString());
tcell.Controls.Add(l1);
trow.Controls.Add(tcell);
tbDynamic.Controls.Add(trow);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
PnlTable.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
PnlTable.Visible = false;
Response.Write(pdfDoc);
Response.End();
}
Output i slike this
________________________________________________________
|- Index |
________________________________________________________
| First Second Third |
| Fourth Fifth Six |
| Seven Eight Nine |
________________________________________________________
I want to apply column line to inside table only not horizontal.If Apply border=1,It will apply border to row as well as column.How to apply that?I already tried rules="clos" and applied boder style to td.But it not working.It is working in html table.But when I converting to pdf,table looses formating
I want like this.
________________________________________________________
|- Index |
________________________________________________________
| First | Second | Third |
| Fourth | Fifth | Six |
| Seven | Eight | Nine |
________________________________________________________
Vertical line break here.I want continuous line