Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using wkhtmltopdf inside asp.net mvc takes a long time to start

I'm using wkhtmltopdf to download a page and create a pdf, as explaind in here. It all works as expected, but when it reaches the following line:

int read = proc.StandardOutput.BaseStream.Read(buffer, 0, buffer.Length);

It takes a very long time to continue. I've also tried the following:

proc.Start();
string output = proc.StandardOutput.ReadToEnd();
string error = proc.StandardError.ReadToEnd();
proc.WaitForExit();

But the same thing happen on line 2 (proc.StandardOutput.ReadToEnd()).

How can i debug this?

Note: As i'm debugging the whole project, i see that the page that is being called by the wkhtmltopdf process only gets called after the delay. So the delay happens between the OS call and the page download itself.


Edit

So i changed the arguments portion to simply http://google.com - and it executed quite fast.

So the problem is somewhere in my full argument: --stop-slow-scripts --redirect-delay 1500 --cookie MOODLEID_ %25E2%25C8%2513E%25BD --cookie ASP.NET_SessionId mg3mfaisk45zn5y1aql0glbb --cookie .ASPXAUTH FEA3D10032E211EDB330E967D8F19A324A912AD792219CA281451AA809F1B580B25466DAF81DE30DF07252FF13F0888C88ED4DB5871579F1DA3EBAA447CBF860131F6FF00A763C9207CE13BCB143301E49A2B00EEBBF1F4AE14F109DF1BE8D3B39C43478B99E4C686C3849D1D51DDBFA3D2E871691BAB8346FE5195D867F88F662F72E40 http://localhost:8404/Relatorio/GeralEstaticoPDF?id=15&pesq_cod=0&IncluirParciais=True&NomesImagens[0]=3fd5b6a2-76a4-470b-af99-93500cc90431.png&NomesImagens[1]=c1c86234-c338-4285-9d25-5069be36a213.png&NomesImagens[2]=4562f9a3-72aa-452c-9736-6d0ba65f59ce.png&NomesImagens[3]=dbc54344-6248-4ee3-9e43-9cb3ef89cc67.png&NomesImagens[4]=8c954917-d572-4d4a-b6fd-2b9cd09e8f8e.png -

I need the cookies to preserve the session.

If i run this directly on command line (but putting in a file name instead of -) it runs fast as well.


Edit 2

So the problem is definitely the cookies, if i remove them it execute fast, BUT it only give me the login screen on the pdf, since it isnt preserving the session.

like image 879
ariel Avatar asked Mar 15 '12 02:03

ariel


1 Answers

PhilJ's answer is correct but, I wanted to add a possible solution for any future visitors.

In short:

Adding the [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)] attribute to the controller (doing the printing) resolved the issue for me.

I'm actually using the Rotativa library which in turn uses wkhtmltopdf.

(It would probably be helpful to add a Rotativa tag to question?)

like image 155
Quinton Smith Avatar answered Sep 20 '22 23:09

Quinton Smith