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

Free Support Forum - aspose.com

Aspose.PDF ignores WIDTH tag of IMG during PDF creation

We have coding that transform html objects to a pdf object, using the aspose.pdf dll. (v9.9.0.0)

But, for a certain image, the width property is ignored during the pdf creation process.

Result is a pdf containing a huge image.

Code :

<img class=\"center\" align=\"center\" border=\"0\" src=\"http://www.sfpd.fgov.be/img/logo.png\" alt=\"[SPFD]\" title=\"[SPFD]\" style=\"outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: block !important;border: none;height: auto;float: none;width: 100%;max-width: 130px\" width=\"130\">

In attachment i deliver
the complete html source that is given to the aspose.pdf dll (html source.txt),
a screenshot of the original HTML (html.jpg),
the code where we use aspose (c#code.txt)
and the result from aspose (result.pdf) .

attachments.zip (363.0 KB)

Peter

@vanbocpe

Thanks for contacting support and sharing files.

We have tried to test the scenario by saving your HTML text file as .html but the HTML string in the text file was not in correct format. Rendered HTML Page did not look same as was in your shared screenshot. HTML.png (7.2 KB) Would you please share complete and correct HTML file (in a ZIP Package) with us, so that we can test it in our environment and address the scenario accordingly.

Furthermore, please also make sure to use latest version of the API i.e. Aspose.PDF for .NET 18.11 as it is always recommended to use latest version. In case issue still persists, please share requested details. We will proceed further to help you out.

HTMLPage.zip (637 Bytes)

@vanbocpe

Thanks for sharing sample HTML.

We have tested the scenario using Aspose.PDF for .NET 18.12 and following code snippet. We were unable to notice any difference in the image width inside PDF. The image to text proportionality was relative in the PDF as it was in source HTML. For you kind reference, we have also attached generated PDF. Would you please check it and share your feedback with us.

var loadoptions = new HtmlLoadOptions();
loadoptions.PageInfo.Width = PageSize.A4.Height;
loadoptions.PageInfo.Height = PageSize.A4.Width;
loadoptions.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);
Document doc = new Document(dataDir + "HTMLPage.html", loadoptions);
doc.Save(dataDir + "outputfromhtml.pdf");

outputfromHTML.pdf (153.7 KB)