Welcome Guest Search | Active Topics | Sign In | Register

HtmlToPdfSession Options
Joakim J
Posted: Tuesday, March 8, 2016 1:13:40 PM
Rank: Newbie
Groups: Member

Joined: 3/8/2016
Posts: 2
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.
eo_support
Posted: Tuesday, March 8, 2016 2:08:04 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

Thanks for the information. We are looking into this and this might be a problem on our side. Please try to switch to the classic engine and see if it works:

http://www.essentialobjects.com/doc/pdf/install/old_engine.aspx

In the mean time we will investigate this and reply again as soon as we have an update.

Thanks!
Joakim J
Posted: Wednesday, March 9, 2016 5:56:43 AM
Rank: Newbie
Groups: Member

Joined: 3/8/2016
Posts: 2
Hi,

thank you for the quick reply.
we've tried using HtmlToPdf.UseClassicEngine() but it didn't solve the problem. Hope you can fix it quickly, this feature is important for our choise of solution.

Best Regards
Joakim J
eo_support
Posted: Wednesday, March 9, 2016 9:05:06 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

Please try to set HtmlToPdf.Options.UserName and HtmlToPdf.Options.Password and see if it works for you. See here for more details:

http://www.essentialobjects.com/doc/pdf/htmltopdf/authenticate.aspx

In the mean time, if you can PM us a test Url, we will look into here and debug into our code to see what went wrong on this.

Thanks!
eo_support
Posted: Saturday, March 12, 2016 9:08:29 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

Please download build 2012.0.21 from our download page. This build fixed a number of issues related to additional headers and authentications.

In this build the following methods should work:

1. Setting HtmlToPdf.Options.UserName and Password;
2. Setting HtmlToPdf.Options.AdditionalHeaders;

This build also added HtmlToPdfSession.RunWebViewCallback method:

http://essentialobjects.com/doc/eo.pdf.htmltopdfsession.runwebviewcallback.aspx

This method exposes the underlying WebView object to you so that you can do almost many things that weren't possible with the old version.

Hope this resolves the issue for you. Please feel free to let us know if you still have any questions.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.