Html to pdf asp.net mvc [closed]

喜欢而已 提交于 2019-12-03 10:01:08
Mujah Maskey

use iTextSharp for C# which is ported from iText from JAVA

check out ITextSharp HTML to PDF?

I've created a project for doing this using iTextSharp, and published on bitbucket.

I override a ViewResult, to return a Pdf stream to the client. The pdf is generated in a MVC View (.cshtml file). And added some Extensions for the controller to make the experience smooth.

I have two options:

  • Create the Pdf from a "normal" view that returns Html. It's very easy, but you do not have "fine" control over the layout.
  • Create a Pdf using code, the layout code is in the View (using server side code). This is easy for customization, and testing. Because you do not need to recompile the whole project. Also IMHO the View (.cshtml file) is responsible for the layout, if the result is html or pdf does not mather, its still the view.

You will need to call RenderView to get the HTML result and then convert to PDF. Check this entry out for a similar solution

http://www.jimzimmerman.com/blog/2009/10/06/PdfResult+A+Custom+ActionResult+In+ASPNET+MVC.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!