【发布时间】:2017-02-06 09:05:35
【问题描述】:
我正在尝试使用 StringWriter 和 HtmlTextWriter 将我的表 (System.Web.UI.WebControls) 放入 pdf,但我得到一个有错误的 pdf 文件。
这是我的代码:
table.RenderControl(htw);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=Reception.pdf");
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
//render the htmlwriter into the response
HttpContext.Current.Response.Write(headerTable);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
打开 pdf 文件时出现“加载文档 pdf 时出错”。
【问题讨论】:
-
错误是什么?为了让任何人帮助您,您必须提供一个完整、最小且可验证的示例。这包括发布可重现的代码以及错误。
-
打开文件时出现“加载文档 pdf 时出错”。
-
什么是sw?它包含一个有效的 pdf 字节数组还是什么?
-
sw 它是 StringWriter & htw 它是 HtmlTextWriter。
-
但它包含什么?