Converting HTML to .JPG, images hosted under authorization

Hello support team,

I’m developing a feature to convert html pages to image.
The images and other resources (.css, .fonts) are hosted under authorization.

My scenario is:

  1. Download the html from the URL with authorization. The authorization methods may be different, for example NTLM, Basic, OAuth and etc. And this is not a problem, because I can download with the .NET WebClient and pass the required authorization.
  2. Pass the html to the Aspose.Html for conversion.
  3. Save result to the disk. The result is that no one image is visible in the converted result .jpg file.

My question: is it possible to pass authorization informaton when Aspose.Html downloads the resources (images, css) from html content? Ideally it would be great to have possibility to attach an external resource resolver with my implementation, but I’m unable to find any information about this in documentation or examples.

My code is very simple:

...
MemoryStream htmlStream = GetHtmlStreamFromUrlWithAuthorization(url, accessToken);

HTMLDocument htmlDocument = new HTMLDocument(htmlStream, string.Empty);

var options = new ImageSaveOptions(ImageFormat.Jpeg);
...
Converter.ConvertHTML(htmlDocument, options, "c:\\temp_files\\result.jpg");
...

Thank you,
Martin

@martin27

We need to investigate the possibility of your requirements. For the purpose, we have logged an investigation ticket as HTMLNET-3665 in our issue management system. We will further look into its details and keep you posted with the status of its resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

@martin27

We would like to share with you that all work with external resources takes place in INetworkService which allows you to register a custom message handler in which you can implement authorization processing. Here is an article on creating and registering them.

As part of such a handler, you can set the necessary Cookies or Credentials in the RequestMessage.

Thank you for the response. It works!

1 Like