I am using one static table which is in a panel conrol
how to convert html content inside the panel to pdf
please help me to convert to pdf as soon as button export is clicked
Aspx code:-
<table width="100%">
<tr>
<td>
<asp:Panel ID="pnlPerson" runat="server">
<table border="1" style="font-family: Arial; font-size: 10pt; width: 200px">
<tr>
<td colspan="2" style="background-color: #18B5F0; height: 18px; color: White; border: 1px solid white">
<b>Personal Details</b>
</td>
</tr>
<tr>
<td>
<b>Name:</b>
</td>
<td>
<asp:Label ID="lblName" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<b>Age:</b>
</td>
<td>
<asp:Label ID="lblAge" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<b>City:</b>
</td>
<td>
<asp:Label ID="lblCity" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<b>Country:</b>
</td>
<td>
<asp:Label ID="lblCountry" runat="server"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
<asp:Button ID="btnExport" runat="server" Text="Export" />
</td>
</tr>
</table>
C#.net Code:-
if (!IsPostBack)
{
//Populate DataTable
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Age");
dt.Columns.Add("City");
dt.Columns.Add("Country");
dt.Rows.Add();
dt.Rows[0]["Name"] = "Mudassar Khan";
dt.Rows[0]["Age"] = "27";
dt.Rows[0]["City"] = "Mumbai";
dt.Rows[0]["Country"] = "India";
//Bind Datatable to Labels
lblName.Text = dt.Rows[0]["Name"].ToString();
lblAge.Text = dt.Rows[0]["Age"].ToString();
lblCity.Text = dt.Rows[0]["City"].ToString();
lblCountry.Text = dt.Rows[0]["Country"].ToString();
}
protected void btnExport_Click(object sender, EventArgs e)
{
}
Please do send me the C# Code for this Export button
Thats what I did and it is creating the pdf as required
Please read this nice article by Scott Mitchell at https://web.archive.org/web/20211020001758/https://www.4guysfromrolla.com/articles/030911-1.aspx and decide what is best for you. As suggested by the author in this article, parsing the HTML and adding it into the PDF has limited support and may not work for complex HTML structures.
Let me know if it helps.