Put your all html code in one Panel which you want to export to the PDF.
Please refer this article.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
y = 5;
z = 2;
x = y + z;
alert(x);
</script>
</head>
<body>
<form id="form1" runat="server">
<script type="text/javascript">
y = 5;
z = 2;
x = y + z;
alert(x);</script>
<asp:Panel ID="pnlExport" runat="server">
<div>
<img src="http://www.aspsnippets.com/images/Blue/Logo.png" /><br />
</div>
<div style="font-family: Arial">
This is a test page</div>
<div>
<table border="1" width="100">
<tr>
<td>
Name
</td>
<td>
Age
</td>
</tr>
<tr>
<td>
John
</td>
<td>
11
</td>
</tr>
<tr>
<td>
Sam
</td>
<td>
13
</td>
</tr>
<tr>
<td>
Tony
</td>
<td>
12
</td>
</tr>
</table>
</div>
<div>
</asp:Panel>
<asp:Button ID="btnExport" runat="server" Text="Export" OnClick="btnExport_Click" /></div>
</form>
</body>
</html>
C#
protected void btnExport_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.pnlExport.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();
Response.Write(pdfDoc);
Response.End();
}
This way Script will not be added in your PDF document.