c# – 使用ASP.NET MVC导出PDF文件

我有一个ASP.NET MVC4应用程序,我想将html页面导出为PDF文件,我使用此代码,它的工作正常: code

代码将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");
}

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...