asp.net – Web窗体中的.NET MVC FileResult等价物
发布时间:2020-05-23 23:21:13 所属栏目:asp.Net 来源:互联网
导读:我正在使用FileResult作为MVC中返回PDF文件的函数的返回值. 我应该在Web窗体中使用什么返回类型? 谢谢 public FileResult PrintPDFVoucher(object sender, EventArgs e) { PdfDocument outputDoc = new PdfDocument(); PdfDocument p
|
我正在使用FileResult作为MVC中返回PDF文件的函数的返回值. 我应该在Web窗体中使用什么返回类型? 谢谢 public FileResult PrintPDFVoucher(object sender,EventArgs e)
{
PdfDocument outputDoc = new PdfDocument();
PdfDocument pdfDoc = PdfReader.Open(
Server.MapPath(ConfigurationManager.AppSettings["Template"]),PdfDocumentOpenMode.Import
);
MemoryStream memory = new MemoryStream();
try
{
//Add pages to the import document
int pageCount = pdfDoc.PageCount;
for (int i = 0; i < pageCount; i++)
{
PdfPage page = pdfDoc.Pages[i];
outputDoc.AddPage(page);
}
//Target specifix page
PdfPage pdfPage = outputDoc.Pages[0];
XGraphics gfxs = XGraphics.FromPdfPage(pdfPage);
XFont bodyFont = new XFont("Arial",10,XFontStyle.Regular);
//Save
outputDoc.Save(memory,true);
gfxs.Dispose();
pdfPage.Close();
}
finally
{
outputDoc.Close();
outputDoc.Dispose();
}
var result = new FileContentResult(memory.GetBuffer(),"text/pdf");
result.FileDownloadName = "file.pdf";
return result;
}
解决方法在ASP.NET Webforms中,您需要手动将文件写入Response流. webforms中没有结果抽象.Response.ContentType = "Application/pdf"; //Write the generated file directly to the response stream Response.BinaryWrite(memory);//Response.WriteFile(FilePath); if you have a physical file you want them to download Response.End(); 此代码未经过测试,但这应该可以帮助您完成大方向. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-routing – @ Url.Action获取?附加长度= 2
- 为什么ASP.NET回发时请求cookie属性为null或不正确?
- 天蓝色 – 不在托管服务或开发结构中运行(生产,而不是调试/
- ASP.NET MVC 2.0 – RenderPartial和RenderAction之间的区别
- 如何在ASP.NET gridview的标题中放置一个按钮?
- asp.net中的会话,缓存和配置文件有什么区别
- asp.net-mvc-5 – aspnet身份避免同时登录同一帐户
- ASP.NET通过自定义函数实现对字符串的大小写切换功能
- asp.net-mvc – ASP.NET MVC:部分知道它是否是从另一个页面
- asp.net – 分类失败.返回未最终内容
推荐文章
站长推荐
- asp.net-mvc – Html.Partial或Html.RenderParti
- asp.net-mvc-3 – 用于制作直方图的库javascript
- 在ASP.NET MVC中测试HtmlHelpers
- asp.net-mvc – 何时使用asp.net mvc的路由规则v
- asp.net-mvc – ASP.NET MVC FluentValidation P
- asp.net-mvc – 从ASP.NET MVC2升级到MVC3的原因
- asp.net-mvc – 类型“表达式”在未引用的程序集
- 在ASP.NET MVC中使用MySQL的AccountController
- asp.net-mvc – 为什么我的View不包括_Layout.cs
- 在IIS / ASP.NET MVC 4中未加载非托管依赖项的64
热点阅读
