PDF生成适用于本地主机但不适用于Web主机

时间:2015-10-15 20:48:31

标签: asp.net-mvc pdf deployment stack-trace rotativa

我正在使用Rotativa生成我的Razor View的pdf。它在我的本地机器上工作正常,但当我将我的网站发布到web主机并尝试生成pdf时,我收到以下错误:

控制器操作方法

 //Generate and output the View pdf file
        public ActionResult PDFCatalogue(int id)
        {
            var productList = db.ProductImages.Include("Products")
                          .Select(m => new ProductDisplayViewModel
                          {
                              ProductId = m.Id,
                              Name = m.Products.Name,
                              ImageUrl = m.URL,
                              Thumbnail = m.URL.Replace(".jpg", "-thumb.jpg"),
                              CategoryId = m.Products.CategoryId,
                              CategoryName = m.Products.Category.CategoryName,
                              Sizes=m.Products.Sizes
                          }).Where(i => i.CategoryId == id).OrderByDescending(m => m.ProductId).ToList();

            TempData["CategoryName"] = db.Category.Where(m => m.Id == id).Select(k => k.CategoryName).SingleOrDefault();
            if (productList == null)
            {
                return HttpNotFound();
            }

            return View("~/Views/Catalogue/PDFCatalogue.cshtml", productList);
            //return new RazorPDF.PdfResult(productList, "~/Views/Catalogue/PDFCatalogue.cshtml");
            //return new MvcRazorToPdf.PdfActionResult("~/Views/Catalogue/PDFCatalogue.cshtml", productList);
        }

        public ActionResult GeneratePDF(int id=0)
        {
            return new Rotativa.ActionAsPdf("PDFCatalogue", new { id = id });
        }

“/”应用程序中的服务器错误。     未处理的执行错误     描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪,以获取有关错误及其在代码中的起源位置的更多信息。

Exception Details: System.Exception:

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[Exception]
   Rotativa.WkhtmltopdfDriver.Convert(String wkhtmltopdfPath, String switches, String html) +975
   Rotativa.WkhtmltopdfDriver.Convert(String wkhtmltopdfPath, String switches) +50
   Rotativa.AsPdfResultBase.CallTheDriver(ControllerContext context) +96
   Rotativa.AsPdfResultBase.BuildPdf(ControllerContext context) +250
   Rotativa.AsPdfResultBase.ExecuteResult(ControllerContext context) +66
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
   System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +23
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
   System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +176
   System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +75
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +99
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31
   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

PS:Rotativa在应用程序的根目录中创建一个目录Rotativa,放置wkhtmltopdf.exe我还将Rotativa目录的权限设置为对应用程序池用户的完全控制权

1 个答案:

答案 0 :(得分:0)

我遇到了一个类似的问题,发现PartialFunction帖子在页面下方表示将生产服务器上的.exe文件替换为下面链接中的.exe文件。这为我解决了这个问题

以下是下载链接this