Search code examples
pdf-generationwkhtmltopdf

wkhtmltopdf and forms based authentication


I have an application that uses forms based authentication. I'm trying to take a copy of a page within the application and save it to PDF using wkhtmltopdf.

wkhtmltopdf is installed and works fine. I can call it successfully from within the application to generate a PDF of another website without authentication (i.e. bbc.co.uk).

I cannot get it to pass username/password to the application in order to generate a copy of the desired page. Instead I get a PDF of the signon screen.

Both client and server are Windows (7 and 2008 respectively). I'm using the command:

wkhtmltopdf.exe --post userid=xxx --post pwd=yyy --ignore-load-errors http://url.com/blah/blah/ test.pdf

Where xxx is my username and yyy is my password. I've been through the source of the logon page and the ids of the form fields are userid and pwd so I believe I have the post parameters in command line correct.

After thoroughly googling I can see mentions to a --cookie-jar parameter, but haven't managed to work out its usage, or even if it'll help.

thanks

Duncan


Solution

  • This issue is now resolved. I was using version 0.9.9 and couldn't get it to work. As soon as I moved to version 0.10.0 rc2 it worked fine.

    If anyone else is trying the same thing, the line of code I used was as above, I didn't need the --cookie-jar parameter.