forum

Home / DeveloperSection / Forums / Getting error to generate pdf

Getting error to generate pdf

Anonymous User 2363 09-Apr-2013
Hi All!

protected void txt_btn_Click(object sender, EventArgs e)
{
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=TestResult.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringBuilder htmlText = new StringBuilder();
    htmlText.Append("<table style='color:red;' border='1'><tr><th>createing pdf</th><tr><td> abcdef</td></tr></table>");
    StringReader stringReader = new StringReader(htmlText.ToString());
    Document doc = new Document(PageSize.A4);
    List<iTextSharp.text.IElement> elements =
            iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(stringReader, null);
    doc.Open();
    foreach (object item in elements)
    {
        doc.Add((IElement)item);
    }
    doc.Close();
    // Response Output
    PdfWriter.GetInstance(doc, Response.OutputStream);
    doc.Open();
    //doc.Close();
    Response.Write("PDF is created");
}
}

I am try to create pdf file.But pdf is created only 0kb.Mean when i open this it's shw error that May be pdf damaged

Thank you in advance!

Updated on 07-Jan-2014
I am a content writter !

Can you answer this question?


Answer

2 Answers

Liked By