Click here to Skip to main content
15,918,193 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m using some code to export web page in pdf.. but i getting error

please help me
Quote:
the error id: input string was not in correct format.

my button click code is:
C#
protected void btn_print_Click(object sender, EventArgs e)
{

    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);
    this.Page.RenderControl(hw);
    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A4, 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 control)
{
    /* Verifies that the control is rendered */
}
Posted
Updated 16-May-14 19:32pm
v2
Comments
karthik Udhayakumar 17-May-14 1:33am    
Put a debugger in your line of code and let know which line throws the error:)to help you out or check this sample post http://www.etechpulse.com/2013/04/how-to-export-web-page-as-pdf-with.html to understand and proceed.
bindash 17-May-14 1:39am    
after debugging the error is

in this line
htmlparser.Parse(sr);

An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code

Additional information: Input string was not in a correct format.

1 solution

 
Share this answer
 

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