Pregunta

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

Any ideas, suggestions?

Regards

¿Fue útil?

Solución

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

check out ITextSharp HTML to PDF?

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top