我对网络处理程序的了解相当少。我所知道的是 Web 处理程序用于创建一些动态文件创建目的。
而且我还知道如何添加 Web 处理程序。
但是,我需要在 ASP.NET 项目中使用 Web 处理程序来创建 PDF。
最佳答案
您可以使用 HTTP 处理程序来提供 PDF,如下所示:
public void ProcessRequest (HttpContext context) {
// Get your file as byte[]
string filename = "....file name.";
byte[] data = get your PDF file content here;
context.Response.Clear();
context.Response.AddHeader("Pragma", "public");
context.Response.AddHeader("Expires", "0");
context.Response.AddHeader("Content-Type", ContentType);
context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", filename));
context.Response.AddHeader("Content-Transfer-Encoding", "binary");
context.Response.AddHeader("Content-Length", data.Length.ToString());
context.Response.BinaryWrite(data);
context.Response.End();
}
关于c# - 如何使用 Web 处理程序创建 PDF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30075075/