mercredi 24 juin 2015

Rotativa.BuildPdf() Causing Access Denied Error

I am trying to save a generated PDF via the BuildPdf() method, so I can save the PDF to a database. I am testing the code below, by running locally in Visual Studio 2013 running IIS Express.

I have scoured the web for solutions, including the Rotativa page on GitHub but to no avail. Perhaps someone else has run into this same issue?

BTW, I get "Access Denied" when running from command line, too:

wkhtmltopdf.exe README.txt test.pdf

I read that a missing C++ dll can cause this error so I checked and I have the file installed, found here:

http://ift.tt/1HeTgXp

Thanks

Here is my link for generating the PDF binary

   <a id="email-me" class="btn icon print"
     href='@Request.Url.GetLeftPart(UriPartial.Authority)@Url.Action("SaveMyViewToDb", "Report",
                         new
                             {
                                 id = 68073,
                                 clubKeyNo = "K10158",
                                 month = 12,
                                 year = 2014
                             }, null)'>@ViewReport.PrintReport</a>

Here is the Action

    public JsonResult SaveMyViewToDb(int? id, string clubKeyNo, int month, int year)
    {

        string fileName = "MyReport";
        var pdfResult = new ActionAsPdf("ViewReport", new { id = id, 
                                                            clubKeyNo = clubKeyNo, 
                                                            month = month, 
                                                            year = year, printMode = true }) 
                                                            { FileName =  fileName + ".pdf" };

        var binary = pdfResult.BuildPdf(this.ControllerContext);

        var saveResult = ReportingDBTasks.SaveDownloadableFileToDb(binary, "pdf", fileName, PersonifyTasks.GetPrimaryEmailString(TaskBase.MasterCustomerId));


       return Json((saveResult ? "Success: Your file is being generated. We will email you once it's ready." : "Error: We were unable to grant your request."));
    }

Here is the stack trace

[Win32Exception (0x80004005): Access is denied] System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) +1789 System.Diagnostics.Process.Start() +6814726 Rotativa.WkhtmltopdfDriver.Convert(String wkhtmltopdfPath, String switches, String html) +459 Rotativa.WkhtmltopdfDriver.Convert(String wkhtmltopdfPath, String switches) +63 Rotativa.AsPdfResultBase.CallTheDriver(ControllerContext context) +102 Rotativa.AsPdfResultBase.BuildPdf(ControllerContext context) +250 Reporting.Controllers.ReportController.SaveMyViewToDb(Nullable1 id, String clubKeyNo, Int32 month, Int32 year) in c:\GitProjects\kiwanisonereporting\Reporting\Controllers\ReportController.cs:1003 lambda_method(Closure , ControllerBase , Object[] ) +335 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +211 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +27 System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +253 System.Web.Mvc.<>c__DisplayClass17.b__14() +21 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary2 parameters) +189 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +324 System.Web.Mvc.Controller.ExecuteCore() +105 Reporting.Controllers.BaseController.ExecuteCore() in c:\GitProjects\reporting\Reporting\Controllers\BaseController.cs:40 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +90 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10 System.Web.Mvc.<>c__DisplayClassb.b__5() +34 System.Web.Mvc.Async.<>c__DisplayClass1.b__0() +19 System.Web.Mvc.Async.<>c__DisplayClass81.<BeginSynchronous>b__7(IAsyncResult _) +10 System.Web.Mvc.Async.WrappedAsyncResult1.End() +62 System.Web.Mvc.<>c__DisplayClasse.b__d() +48 System.Web.Mvc.SecurityUtil.b__0(Action f) +7 System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651796 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Aucun commentaire:

Enregistrer un commentaire