We are currently evaluating different solutions to HtmlToPdf including your Corporate Bundle edition of EO.Total 2016.
But we are experiencing some difficulties when accessing resources on the webserver which need authentication. Specifically we are able to load css and other publicly available resources, however we wish to use Basic Authentication to access protected files (/images/protected_image.jpg) in the example below.
We have tried to add a Basic Authentication header, using HtmlToPdfOptions in the session object, but the request, is missing this header when LoadUrl is called.
We have setup an AutoLogin page for testing purposes, which does not require any credentials, when using this the code works.
How do we make sure that the authorization header is included in the request to AuthenticationPage.aspx?
Below is our example code:
Code: C#
using (HtmlToPdfSession session = HtmlToPdfSession.Create())
{
// when done like this it works
// session.LoadUrl("http://localhost:8081/AutoLogin.aspx");
//when done like this it dosn't work
session.Options.AdditionalHeaders = new string[] { "Authorization: Basic xxxxxxxx" };
session.LoadUrl("http://localhost:8081/AuthenticationPage.aspx");
string str = @"<!DOCTYPE html>
<html>
<head>
<meta http-equiv=""x-ua-compatible"" content=""IE=8"" />
<base href=""http://localhost:8081/"" target=""_blank"">
<title> Udskrift af rekvisition </title>
<meta charset=""utf-8"" />
<link href=""/gfx/dbd.ico"" rel=""shortcut icon"" />
<link href=""../App_Themes/DefaultPrint/printTemplateDefault.css"" type=""text/css"" rel=""stylesheet"" />
</head>
<body>
<div style=""width: 100px; background-color:red;"" class=""Ellipsis"">
loremIpsum loremIpsum
</div>
<img src=""/gfx/ABmidtbyen_Forside.jpg"" alt="""" />
<img src=""/images/protected_image.jpg"" alt="""" />
</body>
</html>";
MemoryStream mem = new MemoryStream();
HtmlToPdf.ConvertHtml(str, mem, session.Options);
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline; filename=test.pdf");
Response.BinaryWrite(mem.ToArray());
Response.Flush();
Response.Close();
Response.End();
}
Hope you can help with this problem.
Best Regards
Joakim J.