c# - 如何使用 Web 处理程序创建 PDF?

标签 c# asp.net web-applications ashx aspx-user-control

我对网络处理程序的了解相当少。我所知道的是 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/

相关文章:

c# - c#中的图形面板

asp.net - 如何在我的新 ASP.NET 网站中使用 OpenID?

facebook - 如何使用 facebook API 获取过去的新闻源?

java - 深层嵌套的 Web 表单验证的模式是什么?

iphone - 关闭 iPhone 网络应用程序

c# - 如何将嵌套 JSON 数据反序列化为扁平对象?

c# - 如何正确地将 IEnumerable<T> 转换为 List<T>?

c# - SSL 的谷歌图表

c# - 何时不使用 lambda 表达式

c# - 错误继承网页控制