我有一个 ASP.NET MVC4 应用程序,我想在其中将 html 页面导出到 PDF 文件,我使用此代码,它工作正常:code http://www.codeproject.com/Articles/260470/PDF-reporting-using-ASP-NET-MVC
此代码将 html 页面转换为在线 PDF,我想直接下载该文件。
我如何更改此代码以获得此结果?
使用 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");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)