【问题标题】:Export asp.net page to pdf issue将asp.net页面导出为pdf问题
【发布时间】:2017-04-15 04:31:38
【问题描述】:

要将页面导出为 Pdf,我从 google 找到了代码。导出后,我将附加信息转换为 pdf 文件。

 Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=TestPage.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.Flush();

以下附加信息显示在底部的我的 pdf 文件中。

//var theForm = document.forms['form1']; if (!theForm) { theForm = document.form1; } 功能 __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } //

在将页面导出为 Pdf 期间如何摆脱上述附加信息?

任何类型的提示或示例代码将不胜感激。

【问题讨论】:

标签: c# asp.net pdf


【解决方案1】:

我遇到了同样的问题。尝试从 aspx 文件中的 asp gridview 中删除 AllowPaging="true" 和 AllowSorting="true"。我的问题解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    • 2013-04-09
    相关资源
    最近更新 更多