Hi nauna,
Refer below sample.
Install or add iron pdf dll reference to your project.
HTML
<form id="form1" runat="server">
<div id="dvCustomers">
<table id="tblCustomers">
<tr>
<th>Customer Id</th>
<th>Name</th>
<th>Country</th>
</tr>
<tr>
<td>1</td>
<td>John Hammond</td>
<td>United States</td>
</tr>
<tr>
<td>2</td>
<td>Mudassar Khan</td>
<td>India</td>
</tr>
<tr>
<td>3</td>
<td>Suzanne Mathews</td>
<td>France</td>
</tr>
<tr>
<td>4</td>
<td>Robert Schidner</td>
<td>Russia</td>
</tr>
</table>
</div>
<br />
<asp:Button ID="btnExport" runat="server" Text="Export" OnClick="btnExport_Click" />
<asp:HiddenField ID="hfHTML" runat="server" />
</form>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#btnExport").click(function () {
$("[id*=hfHTML]").val($("#dvCustomers").html());
});
});
</script>
Namespaces
C#
using IronPdf;
VB.Net
Imports IronPdf
Code
C#
protected void btnExport_Click(object sender, EventArgs e)
{
var Renderer = new IronPdf.HtmlToPdf();
var PDF = Renderer.RenderHtmlAsPdf(hfHTML.Value);
var OutputPath = Server.MapPath("~/HtmlToPDF.pdf");
PDF.SaveAs(OutputPath);
}
VB.Net
Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim Renderer = New IronPdf.HtmlToPdf()
Dim PDF = Renderer.RenderHtmlAsPdf(hfHTML.Value)
Dim OutputPath = Server.MapPath("~/HtmlToPDF.pdf")
PDF.SaveAs(OutputPath)
End Sub