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.
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…
First, let me say I love this package. I will be recommending it to everyone I know that develops in ASP MVC.
ReplyDeleteIs there a way to get it to use @media print css instead of @media all?
Hi Malcom,
Deletethanks for the praise!
You should set this property of the the AsPdfActionResult:
CustomSwitches = "--print-media-type"
Hi, i absolutely love this package!.
ReplyDeleteI have a question here .. My requirement is to combine multiple pages/views into one PDF.
Can that be done with your package?
Hi Amit,
Deletesorry for the late reply. The only thing I can think of is merging the views in a single one, perhaps using Html.RenderPartial.
This comment has been removed by the author.
ReplyDeleteHi, 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?
ReplyDeleteThanks,
Hi Mike,
Deletenext 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.
Ciao,
Giorgio
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.
DeleteThanks, 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.
DeleteThank you so much,
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.
DeleteNew 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,
Hi Giorgio,
ReplyDeleteThis 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?
add key="WkhtmltopdfPath" value="C:\Users\jacaba\Documents\Software\Automata\Automata.WebUI\Scripts\Rotativa\"
DeleteHello Giorgio,
ReplyDeleteIt 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)
Hello Giorgio,
ReplyDeleteA Very good pdf generator, My Question is, How can i add page numbers in that generated pdf pages,