Introducing RazorPDF

-   Oct 15, 2012 -   Development -  

Like many developers, I’ve been working with the Razor View Engine for a while.  Prior to MVC 3 and Razor, I was using Spark as my default view engine and I was pretty happy with it.  Being a long time Spark user, I sometimes find myself wishing I was using Spark for certain things.  The Spark feature I’ve easily missed the most however was the slick way you could uses Spark to mark up iText XML and in turn generate PDFs.

I finally got around to spending a few hours to create this functionality using a Razor view (borrowing heavily from the Spark project). It is very easy to use and makes creating PDFs in your ASP.NET MVC projects a breeze.

  1. Simply add the RazorPDF nuget package to your project.
  2. Have your Controller action return a RazorPDF.PdfResult with your model and view name assigned.
  3. Create the view with itext xml to create the PDF output you want.

Check out this short video showing you RazorPDF in action (2:18) and take a look at the RazorPDFSample project on GitHub to get you going.  The sample project has some basic iText XML samples, but there are plenty more on the web.

12 Comments

Wil Bloodworth
Commented on 10/15/2012 9:58:32 AM
Very nice. Thank you!
jgauffin
Commented on 10/16/2012 1:25:15 AM
Nice
Pierre-Alain Vigeant
Commented on 10/16/2012 10:14:49 AM
That is awesome. I can already make good use of this. I only have to learn iText xml, but that shouldn't be a problem.
Edward
Commented on 10/16/2012 11:01:08 AM
what code theme are you using.
Al Nyveldt
Commented on 10/16/2012 1:12:16 PM
Thanks guys.

Edward, it is the default Dark theme in Visual Studio 2012.  Click, Tools, Options.  Under Environment/General, change the theme to Dark.
Wayne
Commented on 10/20/2012 11:40:22 AM
Are you going to publish the source for the package at github, not just the sample?
Al Nyveldt
Commented on 10/22/2012 9:38:38 AM
Yes. I plan to get the actual project on GitHub soon.  Check back on the blog later this week as I'll make a post when I do.
Edddy
Commented on 10/22/2012 10:03:53 AM
I was wishing for a moment that this was the final response to generate PDF from views, too bad you have to recreate the view in XML instead of using plain HTML.
JP
Commented on 10/23/2012 4:50:59 AM
What is the OS licence type of this project and the libraries it depends on (if any)?
Al Nyveldt
Commented on 10/24/2012 1:55:37 PM
Edddy - You can do some with html as well, but best formatting results are with the iText XML.  I'll try to share some on using html soon.

JP - I'll have this posted on GitHub later this week.  License included. It has a dependency on iTextSharp (which is linked up in the nuget package.)

Thanks for the interest.
Joao Sousa
Commented on 10/26/2012 12:17:30 PM
There is a visual editor for itext? Thank you.
Łukasz
Commented on 11/7/2012 12:39:45 PM
Great job. Thank you.

I have one small question - is it possible to define header/footer in xml?
Or is there any place where all available xml tags are listed?
Comments are closed