Friday, July 27, 2012

What’s new in Rotativa 1.3

What’s new in Rotativa 1.3

The long awaited update of Rotativa has finally arrived. It has important new features, that meet users requests and add new ways of creating Pdf files.
Adding to that I finally managed to add badly needed test automation and I hope I can add more tests in the future.
I should give credit to Scoorf for submitting a nice pull request on GitHub that holds much of the new features. Merging his pull request gave me the opportunity to learn about branches in Git, I should say it’s really easy and very effective and safe way to manage collaborative code.

New features are:

ViewAsPdf action result

This basically works as the normal View action result but you get the Pdf instead of the Html response.

Basic syntax is:
     public ActionResult TestViewAsPdf(string id)  
       var model = new MyViewModel {DocTitle = id, DocContent = "This is a test"};  
       return new ViewAsPdf(model);  
It’s even easier then ActionAsPdf, plus you won’t have problems  with authentication and cookies.

UrlAsPdf action result

This action result enables to return any URL as pdf.

Pdf properties

Now are available new properties for the Action results. Those new properties are:
  • Margins
  • Size
    • Paper size (as in A3, A4 etc)
  • PageWidth and PageHeight
  • PageOrientation
  • Post
    • To set Post values
  • and a handful of others…


  1. First, let me say I love this package. I will be recommending it to everyone I know that develops in ASP MVC.

    Is there a way to get it to use @media print css instead of @media all?

    1. Hi Malcom,

      thanks for the praise!

      You should set this property of the the AsPdfActionResult:

      CustomSwitches = "--print-media-type"

  2. Hi, i absolutely love this package!.
    I have a question here .. My requirement is to combine multiple pages/views into one PDF.
    Can that be done with your package?

    1. Hi Amit,
      sorry for the late reply. The only thing I can think of is merging the views in a single one, perhaps using Html.RenderPartial.

  3. This comment has been removed by the author.

  4. Hi, I'm trying to save the resulting file from ActionAsPdf to the local disk instead of going to the user's browser. What is the easiest way to do that?


    1. Hi Mike,
      next version will have the possibility to save to server. It will be out very soon. I can notify you when it's out if you like.

    2. Mike, just uploaded Rotativa 1.4 to nuget gallery. It has a SaveOnServerPath property that, if set with a valid server file system path, saves the pdf. Sorry for taking more time then expected, hope it helps anyway.

    3. Thanks, I will take a look at that. One other question: Is there a buffer, cookie or clear method I need to call with Rotativa? I ask because in my application the javascript within the view I am passing to ActionAsPDF is not being updated when changes are made to the data.

      Thank you so much,

    4. With my previous question I just got rid of the javascript all together. Thank you, the output from Rotativa is much cleaner than any other method I was using.
      New question: If performance is now my main concern in using Rotativa do you know of any areas that would slow it down? I want to be sure my code is as streamlined as possible. In your experience have you found certain combinations of controller/view code that slows down Rotativa? For example, lots of ViewBag variables or multiple linq to sql queries? Thank you,

  5. Hi Giorgio,

    This is an awesome PDF creator you've made. Works very well. That being said, I have moved my Rotativa folder from the root to another location. I add this to my web config in the root of the site under the tag and it doesn't work. Any ideas?

    1. add key="WkhtmltopdfPath" value="C:\Users\jacaba\Documents\Software\Automata\Automata.WebUI\Scripts\Rotativa\"

  6. Hello Giorgio,

    It is working well on my local machine. But it is giving me unhandled exception on server. I am using 'SaveOnServerPath', where I am giving windows temp path to save the document. This is where I am getting the error.
    at Rotativa.WkhtmltopdfDriver.Convert(String wkhtmltopdfPath, String switches, String html)
    at Rotativa.AsPdfResultBase.CallTheDriver(ControllerContext context)
    at Rotativa.AsPdfResultBase.ExecuteResult(ControllerContext context)

  7. Hello Giorgio,
    A Very good pdf generator, My Question is, How can i add page numbers in that generated pdf pages,