0

I am using ABCPdf 11 to convert html to pdf, my html page which needs to be converted required JWT token so that needs to be passed to ABCChrome so it can use the JWT token. I have tried the following but the auth still fails:

doc.HtmlOptions.HttpAdditionalHeaders = $"Authorization: Bearer {accessToken}";

I followed example from here: https://www.websupergoo.com/helppdfnet/default.htm?page=source%2F5-abcpdf%2Fxhtmloptions%2F2-properties%2Fhttpadditionalheaders.htm

From the description in the above URL, I have also tried the below options:

doc.HtmlOptions.NoCookie = true;
doc.HtmlOptions.Media = MediaType.Screen;

After adding HttpAdditionalHeaders and when I get the http status from the pdf library I do get 401 http status code which confirms the

var imageId = doc.AddImageUrl(model.Url);
var status = doc.HtmlOptions.ForChrome.GetHttpStatusCode(imageId);

The status here is 401 - unauthorized

Umair
  • 4,864
  • 3
  • 28
  • 47

2 Answers2

1

The HttpAdditionalHeaders property is not currently supported by the ABCChrome Engine. The only HtmlOptions supported by ABCChrome are specified here.

There are a few things you could try:

  1. Check whether the target server supports sending the web token via GET request parameters - I guess you've probably done this already :-)
  2. Make the AddImageUrl request URL to an intermediary web server (even a local HttpServer) to a script which can fetch the page for you based on any GET parameters.
  3. If the service you are attempting to access accepts ajax requests you could try using javascript to inject the response into a page using XMLHttpRequest.setRequestHeader(). NB if you use a local file (e.g. file://) for this you may come across some Chromium enforced JavaScript security issues.

I do know that WebSupergoo offer free support for all their licenses, including trial licenses.

Good luck.

Peter G
  • 147
  • 1
  • 10
  • 1
    Thanks, yes I tried downloading html and then converting to pdf and that worked. I added the sample code in a separate answer. – Umair Sep 26 '19 at 11:20
1

Emailed ABCPdf support and unfortunately ABCChrome does not support HttpAdditionalHeaders property so the work around is to download the html ourselves and convert that to PDF, see example below:

var imageId = doc.AddImageHtml(html); // <- html downloaded from auth url

Also don't forget to add paging:

// add all pages to pdf
while (doc.Chainable(imageId))
{
    doc.Page = doc.AddPage();
    imageId = doc.AddImageToChain(imageId);
}

for (int i = 1; i <= doc.PageCount; i++)
{
    doc.PageNumber = i;
    doc.Flatten();
}
Umair
  • 4,864
  • 3
  • 28
  • 47