HTML conversion to PDF containing base64 embedded image

Hi,


I am currently working on a project where we are considering to use aspose to generate PDFs in .NET. However, we’ve come over a problem with converting HTML code containing embedded base64 images.

We’ve seen that other have had the same problem in the past, so we’re just wondering if there is any solution for this, or if there is any planned fix for this.

Hi Andreas,


Thanks for using our products.

Can you please share the source HTML and the code snippet which you are using, so that we can test the scenario at our end. We are sorry for this inconvenience.
Pdf pdf = new Pdf();

Section section = new Section();
pdf.Sections.Add(section);

string html = htmlGenerator.GetHtml();

html = html.Replace("", "\"Red");

Text htmlText = new Text(section, html);
htmlText.IsHtmlTagSupported = true;
section.Paragraphs.Add(htmlText);
pdf.HtmlInfo.ImgUrl = htmlGenerator.getBasePath();
pdf.HtmlInfo.ExternalResourcesBasePath = htmlGenerator.getBasePath();

pdf.Save(ms);


htmlGenerator.GetHtml just retrieves a string containing the html we want to use to generate a PDF. Inside we have a tag for where we want to embed the picture. When we put the html that ends up in the PDF, it is as we expect.

Hi Andreas,

Thanks for sharing the code snippet.

I have tested the scenario where I have used the following code snippet to create a PDF file with Base64 image embedded inside it. I am afraid I am not certain about the contents being returned by htmlGenerator.GetHtml(); method. Please take a look over the attached resultant PDF being generated over my end and confirm that you are also facing similar problem.

[C#]

Pdf pdf = new Pdf();
Section section = new Section();
pdf.Sections.Add(section);

string html;
html = "<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==\" alt=\"Red dot\">";
Text htmlText = new Text(section, html);
htmlText.IsHtmlTagSupported = true;
section.Paragraphs.Add(htmlText);

//pdf.HtmlInfo.ImgUrl = htmlGenerator.getBasePath();
//pdf.HtmlInfo.ExternalResourcesBasePath = htmlGenerator.getBasePath();
pdf.Save("d:/pdftest/HTML_with_Base64_Image.pdf");

Yes, that is how the PDF looks like at my end too.

Hi Andreas,


Thanks for the acknowledgement.

I
have logged it in our issue tracking system as
PDFNEWNET-34213. We will investigate this
issue in details and will keep you updated on the status of a correction.

We
apologize for your inconvenience.

The issues you have found earlier (filed as PDFNEWNET-34213) have been fixed in Aspose.Pdf for .NET 7.8.0update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.