2
Answers

Object reference not set to an instance of an object. Error

Hello,
 
I am developing a project, in that project i want that, after submitting the data, user can generate pdf of that data. I enclosed the data into a panel to generate a pdf. On Generating pdf i am getting an error, and it is 

Object reference not set to an instance of an object.

 my onbuttonclick function is like:
 
protected void btnPdf_Click(object sender, EventArgs e)
{
btnUpload.Visible = false;
FileUpload1.Visible = false;
string attachment = "attachment; filename=" + "abc" + ".pdf";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/pdf";
StringWriter s_tw = new StringWriter();
HtmlTextWriter h_textw = new HtmlTextWriter(s_tw);
h_textw.AddStyleAttribute("font-size", "7pt");
h_textw.AddStyleAttribute("color", "Black");
Panel1.RenderControl(h_textw);//Name of the Panel
Document doc = new Document();
doc = new Document(PageSize.A4, 5, 5, 15, 5);
//FontFactory.GetFont("Verdana", 80, iTextSharp.text.Color.RED);
//FontFactory.GetFont("Verdana", 80, iTextSharp.text.BaseColor.RED);
PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Open();
StringReader s_tr = new StringReader(s_tw.ToString());
HTMLWorker html_worker = new HTMLWorker(doc);
html_worker.Parse(s_tr);
doc.Close();
Response.Write(doc);
}
 
Please help me to resolve this error..
 
Thank You... 
 
Answers (2)