We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Convert HTML to PDF with base64 images

Hi team,


I am trying to convert HTML to PDF format where my HTML contains CSS and Images using the Aspose.Words trial version 14.9.0. The images are in a folder called “…/Resources/Images”. I tried the following.

1. Added base64 string for the png image and supplied the base64 string as img url.
2. Converted png to svg and added the url as background-url:(…/Resources/Images/img.png) in my CSS.

I also generated docx file using the above 2 options but docx file also does not contain any images.

Both of these solutions don’t work. Can you please help me resolve it? How do I reference images in CSS and make Aspose.Words get the images from the right place?


Thanks,
Lakshmi

Hi Lakshmi,


Thanks for your inquiry. In this case, you can use LoadOptions.BaseUri property to resolve relative URIs found in Html into absolute URIs. Please see the following code:

LoadOptions options = new LoadOptions();

options.LoadFormat = LoadFormat.Html;<o:p></o:p>

options.BaseUri = http://www.yoursite.com/Resources/Images/”;<o:p></o:p>

Document doc = new Document(“in.html”, options); <o:p></o:p>

doc.Save(“out.pdf”);

I hope, this helps.

Best regards,