c# – 使用ASP.NET MVC导出PDF文件
发布时间:2020-12-15 04:21:14 所属栏目:百科 来源:网络整理
导读:我有一个ASP.NET MVC4应用程序,我想将html页面导出为PDF文件,我使用此代码,它的工作正常: code 此代码将html页面转换为在线PDF,我想直接下载该文件. 如何更改此代码以获得此结果? 解决方法 使用FileContentResult: protected FileContentResult ViewPdf(s
我有一个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"); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |