Click here to Skip to main content
16,016,229 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Submitbtn_Click(object sender, EventArgs e)
 {
     {                    Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", "attachment;filename=FileName.pdf");
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
 
                StringWriter sw = new StringWriter();
 
                HtmlTextWriter w = new HtmlTextWriter(sw);
                print.RenderControl(w)
 
                string htmWrite = sw.GetStringBuilder().ToString();
                htmWrite = Regex.Replace(htmWrite, "", "");
                htmWrite = htmWrite.Replace("\r\n", "");
                StringReader reader = new StringReader(htmWrite);
 
                Document doc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
                string pdfFilePath = Server.MapPath(".") + "/PDFFiles";
 
                HTMLWorker htmlparser = new HTMLWorker(doc);
                PdfWriter.GetInstance(doc, Response.OutputStream);
 
                doc.Open();
                try
                {
 
                    htmlparser.Parse(reader);
                    doc.Close();
                    Response.Write(doc);
                    Response.End();
                }
                catch (Exception )
                { }
                finally
                {
                   doc.Close();
                }
 

 
        public override void VerifyRenderingInServerForm(Control control)
        {
             /* Verifies that the control is rendered */
        }
}

error shown is:
Error 1 Object reference not set to an instance of an object.
Posted
Updated 8-Jun-14 3:57am
v2
Comments
Kornfeld Eliyahu Peter 8-Jun-14 9:59am    
Why not to debug and find out which object isn't initialized?
[no name] 8-Jun-14 10:00am    
Why not learn how to debug your code instead of reposting the same thing over and over?

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900