Rendering PDF views in ASP MVC using iTextSharp

Generating PDF files can be done by calling iTextSharp classes and methods directly, but consistency with the rest of MVC is preferable. In this post I’m going to explain how you can use iTextSharp to create PDF views the same way HTML views are created. What we need is to write our PDF files under the Views directory using a markup language. iTextSharp supports a special XML format that can be used in our views instead of HTML. One thing to note about aspx is that your tags don’t have to be HTML tags. You can type anything you want; of course Visual Studio will only recognize HTML but the ASP engine will spit that data out to the browser anyway. So, we are going to use regular views but we are going to write iTextSharp XML tags in them instead of HTML. Then we’ll need a way to intercept the result and convert it into PDF before it’s sent to the browser.

Continue reading Rendering PDF views in ASP MVC using iTextSharp

Share