Can you please share the sample HTML file in .zip format along with an expected output PDF? We will test the scenario in our environment and address it accordingly.
It looks like you shared the HTML without resources e.g. images and CSS files. Can you please share the complete package with us so that we can render HTML in the browser in its actual form and test the scenario accordingly?
images are there with the links. I can’t share exact images because of the privacy reasons. I Send this html to aspose.word team also. They gave me solutions for my problems with this HTML.
We replaced the images with our sample image and used below code snippet to generate a PDF file. Please check it and let us know in case it still does not resolve your issue:
string file = dataDir + "CurrentHTMLCode.html";
MemoryStream ms = new MemoryStream(File.ReadAllBytes(file));
Aspose.Html.Saving.PdfSaveOptions options = new Html.Saving.PdfSaveOptions()
{
JpegQuality = 100,
};
options.PageSetup.PageLayoutOptions = Html.Rendering.PageLayoutOptions.FitToWidestContentWidth;
//options.PageSetup.AnyPage.Margin = new Html.Drawing.Margin(30);
//options.PageSetup.AdjustToWidestPage = true;
//options.BackgroundColor = System.Drawing.Color.White;
using (var document = new Aspose.Html.HTMLDocument(ms, dataDir))
{
Aspose.Html.Converters.Converter.ConvertHTML(document, options, dataDir + "ouptut.pdf");
}
We were able to achieve the expected output PDF using the code below:
using (var document = new Aspose.Html.HTMLDocument(File.ReadAllText(dataDir + "CurrentHTMLCode.html"), "."))
{
// Find the paragraph element to set a style attribute
var images = document.GetElementsByTagName("img").Skip(1);
foreach(var img in images)
{
// Set the style attribute
img.SetAttribute("style", "float: left;");
}
// Save the HTML document to a file
document.Save(Path.Combine(dataDir, "edit-inline-css.html"));
string file = dataDir + "edit-inline-css.html";
MemoryStream ms = new MemoryStream(File.ReadAllBytes(file));
Aspose.Html.Saving.PdfSaveOptions options = new Html.Saving.PdfSaveOptions()
{
JpegQuality = 100,
};
options.PageSetup.PageLayoutOptions = Html.Rendering.PageLayoutOptions.FitToWidestContentWidth;
using (var htmldocument = new Aspose.Html.HTMLDocument(ms, dataDir))
{
Aspose.Html.Converters.Converter.ConvertHTML(htmldocument, options, dataDir + "ouptut.pdf");
}
}