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.