HtmlFragment Images?

I was using 11.1.0 before but have since upgraded to 17.11.0

In the old version, I used to create a pdf using pdf generator, add a section and then add a text, set the flag to IsHTMLTagSupported = true. Changed the pdf.HtmlInfo.ImgUrl path to the foolder where my images were and everything would work fine.

Now I’ve upgraded to the latest version I can’t seem to find any of these options.

How would I go about doing this in the latest version? A lot of the documentation seems to be missing and there doesn’t seem to be an example for this.

Can I do this using a HtmlFragment? If so how. Thanks

@quang.dinh

Thanks for contacting support.

In latest version Aspose.Pdf for .NET 17.11, you may use HtmlFragment Class to add html string inside PDF document. Please check following code snippet to add image through HtmlFragment inside PDF.

Document doc = new Document();
Page page = doc.Pages.Add();
HtmlFragment html = new HtmlFragment("<img src='aspose.jpg' />");
// dataDir is the directory where image is located.
html.HtmlLoadOptionsOfInstance = new HtmlLoadOptions(dataDir + @"\\\"); //<---- It is necessary to add last slash at the end of folder
page.Paragraphs.Add(html);
doc.Save(dataDir + "ImageHTML.pdf");

In case of any further assistance, please feel free to let us know.

Thank you, that works fine but I have another issue. It seems to like this function has less features than before? It seems like a lot of CSS options are removed?

@quang.dinh

Thanks for writing back.

In case your HTML string contains inline CSS, HtmlFragment object will render the content in PDF accordingly and in case you want to reference an external CSS file, you may also pass its path to suggested function, so that it can be applied on the HTML content.

However, if you are experiencing any issue while referencing CSS in your HTML, while generating a PDF, please share your sample files (i.e HTML, CSS, Images) in a *.zip package. We will test the scenario in our environment and address it accordingly.