Html to pdf asp.net mvc [closed]

谁说我不能喝 提交于 2019-12-09 07:03:35

问题


I am trying to find a library/tool that would allow me to generate PDF from MVC views.

Any ideas, suggestions?

Regards


回答1:


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

check out ITextSharp HTML to PDF?




回答2:


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.



回答3:


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



来源:https://stackoverflow.com/questions/6660093/html-to-pdf-asp-net-mvc

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