webgio / Rotativa

Rotativa, /rota'tiva/. Make Pdf from Asp.Net MVC. Available on Nuget https://www.nuget.org/packages/Rotativa
http://letsfollowtheyellowbrickroad.blogspot.it/search/label/Rotativa
MIT License
622 stars 220 forks source link

Exception when deployed to server #23

Closed pauldambra closed 9 years ago

pauldambra commented 11 years ago

Apologies if I'm being slow - I've incorporated Rotativa and it works on my dev machine but when I try to use it on the server I receive the below:

Server Error in '/' Application.

Unhandled Execution Error 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:

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) +822 Rotativa.ViewAsPdf.CallTheDriver(ControllerContext context) +1027 Rotativa.AsPdfResultBase.BuildPdf(ControllerContext context) +201 Rotativa.AsPdfResultBase.ExecuteResult(ControllerContext context) +27 Castle.Proxies.ControllerActionInvokerProxy.InvokeActionResult_callback(ControllerContext controllerContext, ActionResult actionResult) +21 Castle.DynamicProxy.AbstractInvocation.Proceed() +69 Glimpse.Mvc3.Interceptor.InvokeActionResultInterceptor.Intercept(IInvocation invocation) +431 Castle.DynamicProxy.AbstractInvocation.Proceed() +204 System.Web.Mvc.<>cDisplayClass1c.b19() +33 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation) +613 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) +263 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +729 System.Web.Mvc.Controller.ExecuteCore() +162 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +159 System.Web.Mvc.<>cDisplayClassb.b5() +62 System.Web.Mvc.Async.<>cDisplayClass1.b0() +15 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +1656 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +540

Server is Server 2008 R2 and application is dotNet 4.5

Call to Rotativa is

return new ViewAsPdf("View", "~/Views/StaffExpenses/_ViewLayout.cshtml", claim) { PageSize = Size.A4, PageOrientation = Orientation.Landscape, PageMargins = {Left = 0, Right = 0, Top = 0, Bottom = 0} };

Both Authenticated Users and the app pool have execute permissions on the files in the Rotativa folder which has deployed to the server with the application.

Project uses Windows Authentication

joostfra commented 11 years ago

Exact the same problem on this side.

Development machine Win7 / VisualStudio 2012 Application ASP.Net MVC4

It works perfect.

Deployed to the server Win Server 2008 R2 Enterprise SP1 IIS 7.5

The executable of 7 day ago, size 8364kb gives the error The executable of 1 year ago, size 6016kb gives no error and creates and serves a pdf.

The error in the eventviewer of the server: Faulting application name: wkhtmltopdf.exe, version: 0.0.0.0, time stamp: 0x4e88ae9d Faulting module name: wkhtmltopdf.exe, version: 0.0.0.0, time stamp: 0x4e88ae9d Exception code: 0xc0000005 Fault offset: 0x01012924 Faulting process id: 0x108 Faulting application start time: 0x01ce05173f56f095 Faulting application path: D:\blokken database\BDB_DEV\BDB_USER V0.28b\Rotativa\wkhtmltopdf.exe Faulting module path: D:\blokken database\BDB_DEV\BDB_USER V0.28b\Rotativa\wkhtmltopdf.exe Report Id: 7d24ddc4-710a-11e2-8042-005056957666

The error in the browser:

Server Error in '/' Application.

Unhandled Execution Error 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:

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) +822 Rotativa.ViewAsPdf.CallTheDriver(ControllerContext context) +1027 Rotativa.AsPdfResultBase.BuildPdf(ControllerContext context) +186 Rotativa.AsPdfResultBase.ExecuteResult(ControllerContext context) +27 System.Web.Mvc.<>cDisplayClass1a.b17() +33 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation) +613 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) +263 System.Web.Mvc.Async.<>cDisplayClass25.b22(IAsyncResult asyncResult) +230 System.Web.Mvc.<>cDisplayClass1d.b18(IAsyncResult asyncResult) +28 System.Web.Mvc.Async.<>cDisplayClass4.b3(IAsyncResult ar) +15 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53 System.Web.Mvc.Async.<>cDisplayClass4.b3(IAsyncResult ar) +15 System.Web.Mvc.<>cDisplayClass8.b3(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.<>cDisplayClass4.b3(IAsyncResult ar) +15 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288


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

webgio commented 11 years ago

That's really bad... tested the new version on my dev machine and not on a server. I'll try ASAP and let you know. Thanks, Giorgio

webgio commented 11 years ago

I tried Rotativa on a Win Server 2008 R2 Standard SP1 and it works... How do you deploy? I used a Web Deploy Package.

joostfra commented 11 years ago

On the development statin I deploy to a local directory. After that I copy the directory to the IIS server. In the IIS manager in the basic settings of the site I point to the right directory.

webgio commented 11 years ago

Could you try to publish a web deploy package and then import it in IIS on server?

joostfra commented 11 years ago

Did it. With a package. Result is the same:

In the eventlog of the server:

Faulting application name: wkhtmltopdf.exe, version: 0.0.0.0, time stamp: 0x4e88ae9d Faulting module name: wkhtmltopdf.exe, version: 0.0.0.0, time stamp: 0x4e88ae9d Exception code: 0xc0000005 Fault offset: 0x01012924 Faulting process id: 0xad0 Faulting application start time: 0x01ce053c46f867b3 Faulting application path: D:\blokken database\BDB_DEV\BDB_USER V0.28c\DBD_USER\Rotativa\wkhtmltopdf.exe Faulting module path: D:\blokken database\BDB_DEV\BDB_USER V0.28c\DBD_USER\Rotativa\wkhtmltopdf.exe Report Id: 8572002a-712f-11e2-8042-005056957666

webgio commented 11 years ago

Sorry, I can't help a lot since I can't reproduce the issue. Did you try to execute wkhtmltopdf.exe from command line?

2013/2/7 joostfra notifications@github.com

Did it. With a package. Result is the same:

In the eventlog of the server:

Faulting application name: wkhtmltopdf.exe, version: 0.0.0.0, time stamp: 0x4e88ae9d Faulting module name: wkhtmltopdf.exe, version: 0.0.0.0, time stamp: 0x4e88ae9d Exception code: 0xc0000005 Fault offset: 0x01012924 Faulting process id: 0xad0 Faulting application start time: 0x01ce053c46f867b3 Faulting application path: D:\blokken database\BDB_DEV\BDB_USER V0.28c\DBD_USER\Rotativa\wkhtmltopdf.exe Faulting module path: D:\blokken database\BDB_DEV\BDB_USER V0.28c\DBD_USER\Rotativa\wkhtmltopdf.exe Report Id: 8572002a-712f-11e2-8042-005056957666

— Reply to this email directly or view it on GitHubhttps://github.com/webgio/Rotativa/issues/23#issuecomment-13237159.

joostfra commented 11 years ago

On the commandline it works:

D:\blokken database\BDB_DEV\BDB_USER\Rotativa>wkhtmltopdf.exe README.txt test.pdf Loading pages (1/6) Counting pages (2/6) Resolving links (4/6) Loading headers and footers (5/6) Printing pages (6/6) Done

D:\blokken database\BDB_DEV\BDB_USER\Rotativa>dir Volume in drive D is Data Volume Serial Number is A483-BA21

Directory of D:\blokken database\BDB_DEV\BDB_USER\Rotativa

07-02-2013 15:17

. 07-02-2013 15:17 .. 06-02-2013 11:34 1.177.600 libeay32.dll 06-02-2013 11:34 43.008 libgcc_s_dw2-1.dll 06-02-2013 11:34 18.207 mingwm10.dll 06-02-2013 11:34 314 README.txt 06-02-2013 11:34 232.960 ssleay32.dll 07-02-2013 15:18 8.051 test.pdf 06-02-2013 11:34 8.564.736 wkhtmltopdf.exe 7 File(s) 10.044.876 bytes 2 Dir(s) 42.479.353.856 bytes free

D:\blokken database\BDB_DEV\BDB_USER\Rotativa>

joostfra commented 11 years ago

It is strange the executable of february last year does work

pauldambra commented 11 years ago

I publish using file system method as my dev box and the server are on the same network. I can run wkhtmltopdf from the command line on the server.

I wonder if it's a permissions issue.

Although, I'm using authenticationMode = "windows" and both with and without ASP .NET impersonation enabled I get the error.

webgio commented 11 years ago

Can you create some sample vs solution to test for me?

2013/2/7 joostfra notifications@github.com

It is strange the executable of february last year does work

— Reply to this email directly or view it on GitHubhttps://github.com/webgio/Rotativa/issues/23#issuecomment-13237588.

joostfra commented 11 years ago

ok here is a basic mvc app

tested and produces the error.

Where can i upload the zip ?

webgio commented 11 years ago

send it to me at: giorgio.bozio@gmail.com

2013/2/7 joostfra notifications@github.com

ok here is a basic mvc app

tested and produces the error.

Where can i upload the zip ?

— Reply to this email directly or view it on GitHubhttps://github.com/webgio/Rotativa/issues/23#issuecomment-13238671.

pauldambra commented 11 years ago

made a test project and it won't run locally which makes me think the problem is between my chair and my keyboard.

Have mailed you a 7z of the project.

webgio commented 11 years ago

@joostfra Tried your code and it works for me.. sorry... using Windows Server 2008 standard R2 SP1.

@pauldambra I get an error using your code: "Qt: Untested Windows version 6.2 detected!", seems something related to the compilation of Qt used for building wkhtmltopdf. I tried to repro with a clean project on VS2012 but couldn't.

pauldambra commented 11 years ago

Strange! I'm on Windows 7 which is 6.1.

Are you adding via nuget when trying to repro?

pauldambra commented 11 years ago

So, I've been playing around and on the server I see the error:

Application popup: wkhtmltopdf.exe - Application Error : The instruction at 0x01412924 referenced memory at 0x00000024. The memory could not be written.

If I run wkhtmltopdf http://intranet.thebmc.co.uk/StaffExpenses/View/33 viewoutput.pdf at the commandline

I get:

Loading pages (1/6) Error: Authentication Required Error: Failed loading page http://intranet.thebmc.co.uk/StaffExpenses/View/33 (sometimes it will work just to ignore this error with --load-error-handling ignore)

So, I guess Rotativa is hitting that same error?

pauldambra commented 11 years ago

@joostfra are you in the same boat as me then? Integrated windows authentication and anonymous auth disabled?

@webgio I think that's the problem for me that anonymous or web forms auth is required.

pauldambra commented 11 years ago

yep, enabling anonymous authentication fixes PDF generation on the server too.

joostfra commented 11 years ago

For me is windows authentication enabled and anonymous authentication disabled. So, the anonymous authentication should be enabled ? But this should be disabled for windows authentication to work correctly.

joostfra commented 11 years ago

Some more testing give the following: Anonymous Authentication enabled, does not solve the problem. Windows Authentication disabled, the application does not work anymore.

And we need the windows authentication, for the single sign-on.

joostfra commented 11 years ago

How is it possible, the executable of last year does not produce this error ? Does the executable maybe try to create a temp file, and is that permitted by the server ?

joostfra commented 11 years ago

@webgio: when i publish the test app and use anonymous authentication, it works. And when I enable the windows authentication, it works. But when I disable the anonymous authentication, the error is there again.

Maybe this info can help.

webgio commented 11 years ago

Ok joosfra, I'll try to repro myself and, if the problem lies in the wkhtmltopdf version, I'll file a issue to them. Thanks.

pauldambra commented 11 years ago

Looks like it's known about http://code.google.com/p/wkhtmltopdf/issues/detail?id=337

webgio commented 11 years ago

Paul, it's strange though that the previous version worked, the issue you found dates back to 2010.

Zache commented 11 years ago

I'm having what I think is similiar issues, I'm using basic authentication and https and cannot get it working when deployed to our IIS. Using the new BuildPdf and returning the bytes doesn't work either.

webgio commented 11 years ago

Zache, basic auth should work, the problem here seems to be about disabling the anonymous authentication. Is this your case too?

2013/2/14 Zache notifications@github.com

I'm having what I think is similiar issues, I'm using basic authentication and https and cannot get it working when deployed to our IIS. Using the new BuildPdf and returning the bytes doesn't work either.

— Reply to this email directly or view it on GitHubhttps://github.com/webgio/Rotativa/issues/23#issuecomment-13544117.

Zache commented 11 years ago

I enabled anonymous auth, but it's still broken.

manuelnelson commented 11 years ago

Ran into this issue as well. Not the most elegant solution, but you can pass a windows authenticated username and password into the CustomSwitches Property like so

var switches = @" --username " + ConfigurationManager.AppSettings["PdfUserName"] + " --password " + ConfigurationManager.AppSettings["PdfPassword"];

var pdfStream = new ViewAsPdf("ClientAuditInvoicePdf", auditInvoiceView)
{
            PageMargins = new Rotativa.Options.Margins(13, 13, 13, 13),
            FileName = "pdfName.pdf",
            CustomSwitches = switches
};

This will enable the PDF to be generated. See the comments section of this post for more information

iekzaer commented 11 years ago

Hi friends

I have the same issue, i have a hosting with godaddy and i can't generate the pdf file, in my test & development environment it works perfectly, but when i upload the deploy to godaddy the exception appears.

Currently i work with forms authentication and i think that the wkhtmltopdf.exe file isn't run in godaddy servers for the permissons.

Somebody knows about how to fix this issue?

Really appreciate your help to solve this.

Alfred

México

t3b4n commented 11 years ago

Hello, I'm facing the same issue and can not solve it by using the CustomSwitches. In my development machine (Windows 8, VS2010, connected to a SQLServer 2008 database) everything works fine. I have a method that creates PDFs from views and save it to the disk, so I can print it later, but when I pass the project to the server it can't create the PDF.

The production server is a Windows 2003 (IIS6), connected to a SQLServer 2005 database. It has Windows Authentication activated but I've also activated anonymous access.

If I run wkhtmltopdf from the command line in the server, including the same CustomSwitches, the PDF is created without any troubles. But when I use it with Rotativa in my project it does not produce any PDF. On the production server no exception is being thrown so I can't provide any error messages.

Can you please help me?

arwakatungu commented 10 years ago

same issue. No resolution

celsojr commented 10 years ago

Hi,

I have replaced the "wkhtmltopdf.exe" from the server with my local copy of the same executable. It worked to me.

You can find it by doing a fast search in your local project folder and then send a copy to the server folder through remote access without help of the Visual Studio.

Hope this help! Take care!

webgio commented 10 years ago

I've update wkhtmltopdf to version 0.12. Did it in a new branch (you can find it here too) and deployed a new nuget package in "pre release" mode. So you can install by running

Install-Package Rotativa -Pre

in the nuget package manager console.

It would be nice to have some feedback on this, so I can release it as a main version.

Thanks, Giorgio

mortenholmgaard commented 10 years ago

I tried it - got this error message: Failed loading page ... (sometimes it will work just to ignore this error with --load-error-handling ignore) Exit with code 1 due to http error: 1099

Couldn't figure out what the error code mean..

For me it works fine on dev and stage and even on prod accessed from localhost url - but not the external url.

webgio commented 10 years ago

@mortenholmgaard that could be a dns problem. Are you using ActionAsPdf?

mortenholmgaard commented 10 years ago

@webgio No I am using: new UrlAsPdf("/PrintVisitOrder?orderedChrNumbers=" + orderedChrNumbers); What kind of dns problem are you considering?

webgio commented 10 years ago

@mortenholmgaard UrlAsPdf will use the hostname contained in the http request and if that name is not resolved on the server then you have a problem. You could login to the server machine and try name resolution there.

mortenholmgaard commented 10 years ago

@webgio You are right - name resolution issues. Thanks, and sorry - I thought it was related to this issue.

celsojr commented 10 years ago

@webgio I have updated the project I'm working on with your "pre release". The problem seems to be solved! The only detail now is this message in the Output Window:

The item [my local path mapping by TFS]\packages\Rotativa.1.6.1 could not be found in your workspace, or you do not have permission to access it.

The item [my local path mapping by TFS]\packages\Rotativa.1.6.1 could not be found in your workspace, or you do not have permission to access it.

The same message two times... It happens each time I open the solution from the Source Control Explorer

celsojr commented 10 years ago

@webgio The problem is back :/ This week it happened two times. I have solved it by replacing the .exe Hope it can be definitely solved... Any other update?

PS: If you need more details on these errors (the Event Viewer information in a confidential way), just send me an e-mail at celsojrfull [ at ] gmail [ dot ] com Thanks

habiat commented 10 years ago

for the error "The directory name is invalid" You need the Rotativa folder in the root of the web app, or if different provide the path in web.config.

ahmad1984 commented 9 years ago

Rotativa uses a temporary directory that names 'Rotativa' in root folder of the website or project. You must have this folder in your project or website. It contains these files: libeay32.dll libgcc_s_dw2-1.dll mingwm10.dll README.txt ssleay32.dll wkhtmltopdf.exe

chriscarreau commented 9 years ago

Had a similar error, where it went fine on my local machine, but didn't work on the server. Turns out the only thing I had to do was to install the Visual C++ Redistributable Packages for Visual Studio 2013 on the server because rotativa needed it.

bjarte commented 9 years ago

@chriscarreau: Thanks, installing Visual C++ 2013 helped me as well. I had the same problem, things worked nicely locally, but not on the server (where Visual Studio is not installed).

ahmad1984 commented 9 years ago

Have you added a folder named "Rotativa" in your website?

like this: untitled

scottycroy commented 9 years ago

FWIW,

I had the same issue as described in this post. I installed the nuget package from within Visual Studio 2013. Hosting on Server 2008 R2.

@ahmad1984 mentioned I needed the other files in the Rotativa folder in the root of the web. The files that @ahmad1984 mentioned was not included in the nuget package.

I downloaded the git package and found the files in

..\Rotativa-master\packages\Rotativa.1.0\content\Rotativa folder

I uploaded the files, but it still did not work.

I then downloaded wkhtmltopdf for x64 bit. Uploaded the files: wkhtmltoimage.exe wkhtmltopdf.exe wkhtmltox.dll

Now this issue is resolved and everything works for me.

ghost commented 9 years ago

I am having this same issue, but with wkHtmltoImage instead of PDF. It works fine locally, but just crashes with an exception on the server. I'm running in only Anonymous Auth mode on Sever 2012. I have another project on this server that runs Rotativa, and it generates PDFs perfectly.

Stack trace:    at Rotativa.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html, String wkhtmlExe)
   at Rotativa.WkhtmltoimageDriver.ConvertHtml(String wkhtmltopdfPath, String switches, String html)
   at Rotativa.ViewAsImage.CallTheDriver(ControllerContext context)
   at Rotativa.AsResultBase.BuildFile(ControllerContext context)
   at LobbyKiosk.Controllers.HomeController.CreateIdCard(Int32 Visitor)
   at LobbyKiosk.Controllers.HomeController.Index(Nullable`1 Id)
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
claudiomaia commented 9 years ago

Para quem utiliza Asp.Net.MVC, volte a versão para 1.6.1 do rotativa que irá funcionar no servidor. Foi a solução que encontrei para resolver o problema (pelo menos por enquanto)

For those who use Asp.Net.MVC update in nuget to 1.6.1 of Rotativa that will work on the server. It was the solution I found to solve the problem (at least for now).