0

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

I am getting this error when i am trying to create PDF of the page HTML using iTextSharp.

Any one has any idea how to resolve it?

This is my button click event in which i create PDF.

 protected void Button1_Click(object sender, EventArgs e)
        {
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=Filename.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            //Render PlaceHolder to temporary stream
            StringWriter stringWrite = new StringWriter();
            HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            PlaceholderPdf.RenderControl(htmlWrite);
            StringReader reader = new StringReader(stringWrite.ToString());
            //Create PDF document
            Document doc = new Document(PageSize.A4);
            HTMLWorker parser = new HTMLWorker(doc);
            PdfWriter.GetInstance(doc, Response.OutputStream);
            doc.Open();

            try
            {
                //Create a footer that will display page number
                //Parse Html
                parser.Parse(reader);

            }
            finally
            {
                doc.Close();
            }
        }

Thanks in advance

4

0 回答 0