Aspx.net转pdf

时间:2016-11-30 17:16:23

标签: c# asp.net pdf itext

您好我正在尝试将当前运行的aspx页面转换为pdf。我尝试了很多代码,但它不起作用。其中之一是 -

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition","attachment;filename=Panel.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);


panel1.RenderControl(hw);
panel2.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();

如果我添加每个面板它即将到来,但仍然有一些数据进入面板,如表格内容不在pdf中。我甚至试过 - “this.Page.RenderControl(hw);

但它显示错误:只能在Render()

期间调用RegisterForEventValidation

所以请建议我实现它的方式。

0 个答案:

没有答案