Search code examples
htmlcssasp.net-mvcwkhtmltopdfrotativa

Rotativa had problems with css style on server


I am using Rotativa in my ASP.net MVC project. I am using ViewAsPDF as return type. The problem is that on local enviroment everything runs smoothly, the css style is getting applied to PDF correctly, but when I deploy my app on prod server and I try to get PDF file, server returns it only after ~ 5 minutes without CSS style applied. If I gave style straight to the atribute <td style="..."> it works. Where can I find the problem, and how to solve it?

Thanks!

Update: if I delete links to CSS stylesheets, it works much faster:

Update: if I run wkhtmltopdf.exe manually on any of my site pages i get this:

%computername% | D:\Projects\myapp\trunk\WebSite\Rotativa>wkhtmltopdf http://myappp.com pdf.pfd
Loading pages (1/6)
Error: Failed loading page http://finishgenius.tizbi.com (sometimes it will work just to ignore this error with --load-error-handling ignore)

Update: if I change method ViewAsPdf to ActionAsPDF I am getting error:

Server Error in '/' Application.

Error: Failed loading page http://myapp.com/FinishingSchedules/PrintScheduleDetails/2?Name=Schedule No.2&CostPerSquareFootMaterial=0.06&CostPerSquareFootLabor=54&DirectCostOfMaterialsAndLabor=108.12&TotalPriceWithMarkUp=118.93&TotalJobSize=2&ProductionTime=36&MaterialsQuantities=System.Collections.Generic.List`1[WebSite.ViewModels.FinishingSchedules.MaterialsQuantities] (sometimes it will work just to ignore this error with --load-error-handling ignore)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Exception: Error: Failed loading page http://myapp.com/FinishingSchedules/PrintScheduleDetails/2?Name=Schedule No.2&CostPerSquareFootMaterial=0.06&CostPerSquareFootLabor=54&DirectCostOfMaterialsAndLabor=108.12&TotalPriceWithMarkUp=118.93&TotalJobSize=2&ProductionTime=36&MaterialsQuantities=System.Collections.Generic.List`1[WebSite.ViewModels.FinishingSchedules.MaterialsQuantities] (sometimes it will work just to ignore this error with --load-error-handling ignore)


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: Error: Failed loading page http://myapp.com/FinishingSchedules/PrintScheduleDetails/2?Name=Schedule No.2&CostPerSquareFootMaterial=0.06&CostPerSquareFootLabor=54&DirectCostOfMaterialsAndLabor=108.12&TotalPriceWithMarkUp=118.93&TotalJobSize=2&ProductionTime=36&MaterialsQuantities=System.Collections.Generic.List`1[WebSite.ViewModels.FinishingSchedules.MaterialsQuantities] (sometimes it will work just to ignore this error with --load-error-handling ignore)
]
   Rotativa.WkhtmltopdfDriver.Convert(String wkhtmltopdfPath, String switches, String html) +570
   Rotativa.AsPdfResultBase.CallTheDriver(ControllerContext context) +26
   Rotativa.AsPdfResultBase.BuildPdf(ControllerContext context) +128
   Rotativa.AsPdfResultBase.ExecuteResult(ControllerContext context) +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +52
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +173
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +28
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
   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() +9633216
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18067 

Solution

  • Finally found where the root of my problem were. I tried to visit my website from server's browser, and I found out that server does not see himself. I updated the hosts.txt file with proper IP adress and that fixed my problem. Hope this will help someone! Thanks!