Question

I am trying to save a page of our application as PDF. The page has data about the currently logged in member but when I pass the page url to wkhtmltopdf the new process isn't logged in so can't see that data.

Is it possible to have wkhtmltopdf log in as a specific member? I've tried using the username and password parameters but these are for basic http auth and don't seem to have any effect.

I am using https://github.com/codaxy/wkhtmltopdf to wrap wkhtmltopdf. My usage:

string filename = "file.pdf";
MemoryStream memory = new MemoryStream();
PdfDocument document = new PdfDocument() { Url = Request.Url.AbsoluteUri };
PdfOutput pdfoutput = new PdfOutput() { OutputStream = Response.OutputStream };

PdfConvert.ConvertHtmlToPdf(document, pdfoutput);

Response.ContentType = "Application/pdf";
Response.AppendHeader("content-disposition", "attachment; filename=" + filename);
Response.End(); 
Was it helpful?

Solution

I found a way to include the auth cookie into the wkhtmltopdf process:

// Authentication
paramsBuilder.Append("--cookie " + System.Web.Security.FormsAuthentication.FormsCookieName + " " + umbraco.library.RequestCookies(System.Web.Security.FormsAuthentication.FormsCookieName) + " ");

Seems to do the trick!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top