I was using this Rotativa 1.6.4 code example to generate a PDF from a page in my .NET MVC 5 app.
public ActionResult PrintIndex()
{
var a = new ActionAsPdf("Index", new { name = "Giorgio" }) { FileName = "Test.pdf" };
a.Cookies = Request.Cookies.AllKeys.ToDictionary(k => k, k => Request.Cookies[k].Value);
a.FormsAuthenticationCookieName = System.Web.Security.FormsAuthentication.FormsCookieName;
a.CustomSwitches = "--load-error-handling ignore";
return a;
}
public ActionResult Index(string name)
{
ViewBag.Message = string.Format("Hello {0} to ASP.NET MVC!", name);
return View();
}
It was not printing the Index page, but instead was printing my login page.
Once I fixed the authentication issue, PDF generation was extremely slow even with CustomSwitches
. (Several minutes)
The above code might actually work for you - it got around the authentication issue using the Cookies
property, but it was way too slow for me.
How do I print a secure page as well as do it quickly?