At last i have exported the UpdatePanel in that aspx page to pdf file instead of exporting the whole page to pdf .If I am writing "this.Page" instead of "UpdatePanel1" it results in an exception Unable to cast object of type '
iTextSharp.text.html.simpleparser.CellWrapper
' to type'
iTextSharp.text.Paragraph
'.
protected void imgbtnprint_Click(object sender, ImageClickEventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
UpdatePanel1.DataBind();
UpdatePanel1.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 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();
}
public override void VerifyRenderingInServerForm(Control txt_salutaion)
{
}