创建pdf usingitext sharp时出错

时间:2013-11-14 06:50:06

标签: c# asp.net pdf pdf-generation itextsharp

  

Microsoft JScript运行时错误:   Sys.WebForms.PageRequestManagerParserErrorException:消息   从服务器收到的邮件无法解析。常见原因   错误是通过调用Response.Write()修改响应时,   启用了响应过滤器,HttpModules或服务器跟踪。

当我尝试使用iTextSharp创建页面HTML的PDF时,我收到此错误。

任何人都知道如何解决它?

这是我创建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();
            }
        }

提前致谢

0 个答案:

没有答案