Lam*_*fif 6 .net c# asp.net-mvc razor
我有一个ASP.NET MVC4应用程序,我想在其中导出一个HTML页面到PDF文件,我使用这个代码,它的工作正常:代码
此代码将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");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20372 次 |
| 最近记录: |