使用ASP.NET MVC导出PDF文件 [英] Exporting a PDF-file with ASP.NET MVC
本文介绍了使用ASP.NET MVC导出PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ASP.NET MVC4应用程序,我想在其中将html页面导出为PDF文件,我使用此代码,并且效果很好:
I have an ASP.NET MVC4 application in which I'd like to export a html page to PDF-file, I use this code and it's works fine: code
此代码将html页面转换为在线PDF,我想直接下载文件.
This code converts a html page to online PDF, I'd like to download directly the file.
如何更改此代码以获得此结果?
How can I change this code to obtain this result?
推荐答案
带有FileContentResult:
With a FileContentResult:
protected FileContentResult ViewPdf(string pageTitle, string viewName, object model)
{
// Render the view html to a string.
string htmlText = this.htmlViewRenderer.RenderViewToString(this, viewName, model);
// Let the html be rendered into a PDF document through iTextSharp.
byte[] buffer = standardPdfRenderer.Render(htmlText, pageTitle);
// Return the PDF as a binary stream to the client.
return File(buffer, "application/pdf","file.pdf");
}
这篇关于使用ASP.NET MVC导出PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文