0
votes

I have this HTML:

<table style="width:100%" class="table table-bordered"><tbody><tr><td><p><img src="/User/Images/logo-48_20200612183312_78003.jpg" style="width: 64px;"></p></td><td><p>Development, Systems &amp; Technologies</p><p>Santiago</p></td></tr></tbody></table>

That HTML only includes the text in the generated PDF file, bypassing the image.

This is the code I am using to convert that paragraph:

    private IList<IElement> ConvertHtmlToElements(string html)
    {
        ConverterProperties properties = new ConverterProperties();
        properties.SetBaseUri(HttpContext.Current.Server.MapPath("/"));

        return HtmlConverter.ConvertToElements(html, properties);
    }

I am using iText7 7.1.11 and iText7.pdfhtml 3.0.0.

I should also tell you that this same code works perfectly, with the same image, using iText7 7.1.2 and iText7.pdfhtml 2.0.2.

Something has changed between those versions?

Of couse the image is accesible using https://server/User/Images/logo-48_20200612183312_78003.jpg

Jaime

1
Hi Jaime, do you have any warnings/errors in the logs? You can configure logging with instructions at github.com/net-commons/common-loggingAlexey Subach
@AlexeySubach I have found out the problem. When calling to properties.SetBaseUriusing a physical path that ends in backslash and the IMG SRC attribute starts with a /, images are not rendered in the PDF. To solve it, I have used this call for the HTML: html = html.Replace("img src=\"/", "img src=\"");.... I don't really know why if I remove only the last backslash at the end of the physical path, it does not work either. I had to remove the / to the beginning of the IMG SRC path. Maybe, it is due because this is Window and physical path uses backslash while the IMG SRC uses slash.jstuardo

1 Answers

0
votes

Finally, it turned out that in the last version of iText7 (iText7 7.1.11 and iText7.pdfhtml 3.0.0) it is important that the SRC attribute of the IMG tag should not start with a slash.