Image missing in generated PDF from HTML

We are converting HTML to PDF. The HTML has an image tag as follows:

<img src="<Site URL>/TestLibrary/test.jpg"  alt="test" > OR 

<img src="<Site URL>/TestLibrary/test.jpg"  alt="test"  />

The image is present in a SharePoint Document library. On the HTML page, we can view the image properly.

When the PDF is generated using the HTML, we are not seeing the image in the generated PDF. It is missing.


Thanks for contacting support.

While converting HTML to PDF, it is necessary to define a base path to HTML resources (CSS, Images) in constructor of HtmlLoadOptions class. So in your case the instantiation of class would be as follows:

Aspose.Pdf.HtmlLoadOptions options = new Aspose.Pdf.HtmlLoadOptions("<Site URL>/TestLibrary/");

Please use above suggested approach to generate PDF from HTML and in case you still face any issue, please share your sample HTML file (in a ZIP archive), so that we can test the scenario in our environment and address it accordingly.

We are using the following sample code to generate the PDF:

string HTMLValue; //This has the img tag.
HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions();
IO.MemoryStream ioStream = new IO.MemoryStream(Encoding.UTF8.GetBytes(HTMLValue)
Document pdfDocument = new Document(ioStream, htmlLoadOptions);

The image is present when the code runs first time but on further runs the image is not there in the generated PDF.


Thanks for writing back.

The code may produce correct output in case img tag contains full path to source image (e.g <img src='' />) and problem will occur in case image path is defined within a project domain (e.g <img src='images/someimage.png' />).

As shared earlier, please try defining base path in HtmlLoadOptions instantiation and if you still experience similar issue, please share your sample HTML file with us, so that we can test the scenario in our environment and address it accordingly.

We are providing complete URL and we have tried using the base path in HTMLLoadOptions but it has not worked. I cannot share the HTML file due to client restrictions. But you can refer any image file stored in SharePoint Document Library in your HTML as below and then try and convert it to PDF.

<img src="<Site URL>/TestLibrary/test.jpg" alt="test" >


Thanks for getting back to us.

We are working over testing the scenario and as soon as we have our findings to share with you, we will let you know. Please spare us little time.

We are sorry for this inconvenience.

Dear Team,

Request you to provide update on this issue ASAP.


Thanks for your patience.

We have tested the scenario with Aspose.Pdf for .NET 17.11, by using an image URL (hosted over SharePoint site) and were unable to replicate the issue. Each time, code generated an output PDF with an image. Would you please share an URL of the image which you are trying to add inside PDF through HTML? We will test the scenario with specific URL and let you know about our findings.


Adding more to my previous comments, it would really be helpful if you can please share a sample project with sample HTML file(s). In case you cannot share original HTML file due to some restrictions, you may please use a sample HTML with which issue is reproducible. We will test the scenario in our environment and address it accordingly.

PS: You may also share your files in a private message, so that they will only be accessible to Aspose Staff.

Hi Team,

We are trying to generate PDF from HTML which is having Image in SharePoint Library in SharePoint Online. It seems to be issue with authentication,

Can you please share your code sample which covers authentication with SharePoint Online site for our reference so that we can take a look?


Thanks for getting back to us.

In case you are downloading your HTML and need authentication to establish a connection with server, please check “Provide Credentials while converting HTML to PDF” article in our API documentation. In case you still experience any issue, as requested earlier, please share a sample project with complete code snippet, that could help us in replicating the issue in our environment and address it accordingly.