First add reference to your application (itextsharp.dll)
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
// Type this code on button's click
protected void ImgBtnExport_Click(object sender, ImageClickEventArgs e)
{
string filename=txtReportName.text;
string attachment = "attachment; filename=" + filename+ ".pdf";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/pdf";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
htextw.AddStyleAttribute("font-size", "7pt");
htextw.AddStyleAttribute("color", "Black");
Panel_Name.RenderControl(htextw);//Name of the Panel
Document document = new Document();
document = new Document(PageSize.A4, 5, 5, 15, 5);
FontFactory.GetFont("Arial", 50, iTextSharp.text.BaseColor.BLUE);
PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
StringReader str = new StringReader(stw.ToString());
HTMLWorker htmlworker = new HTMLWorker(document);
htmlworker.Parse(str);
document.Close();
Response.Write(document);
}
//Paste this code some where on page
public override void VerifyRenderingInServerForm(Control control)
{
}
Regards
Nidhin Das K (Assyst International).