Margin issue when saving html as image

Hi, I am using the following code to save html as image.
The picture’s left margin is over 5.The margin is around 15. Is this caused by the following screenshot?
image.png (22.7 KB)

var options = new ImageSaveOptions(ImageFormat.Jpeg);
options.PageSetup.AnyPage.Margin = new Margin(5, 5, 5, 5);

@tommylu

Would you please share your sample HTML with us? We will test the scenario in our environment and address it accordingly.

Hi @asad.ali ,
please check the following information.
960 * 384 is the dimension of test html.

 // Initialize an HTML document from the html file
 using (var document = new Aspose.Html.HTMLDocument(@"C:\\test.html"))
 {
     // Initialize ImageSaveOptions 
     var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg);
     options.PageSetup.AnyPage.Size = new Size(960 + 20, 384 + 20);
     options.PageSetup.AnyPage.Margin = new Margin(5, 5, 5, 5);
     //options.Css.MediaType = Rendering.MediaType.Screen;
     // Convert HTML to JPG
     Aspose.Html.Converters.Converter.ConvertHTML(document, options, "output.jpg");
 }

test.7z (1.5 KB)

@tommylu

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): HTMLNET-5162

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hi @asad.ali ,any update about this issue?

@tommylu

The ticket has recently been logged in our issue tracking system and it will be prioritize on first come first serve basis. As soon as we make some progress towards its resolution, we will update you. Please spare us some time. We are sorry for the inconvenience.

@tommylu

We have investigated the logged ticket. This happens because the body element’s margins are 8px by default. To reset them, you need to add the following style to the document: “body { margin: 0px; }”. The following code snippet shows how this can be done programmatically:

var configuration = new Configuration();
configuration.GetService<IUserAgentService>().UserStyleSheet = "body { margin: 0px; }";

using (var document = new Aspose.Html.HTMLDocument(@"C:\\test.html", configuration))
{
     // Initialize ImageSaveOptions 
     var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg);
     options.PageSetup.AnyPage.Size = new Size(960 + 10, 384 + 10);
     options.PageSetup.AnyPage.Margin = new Margin(5, 5, 5, 5);
     //options.Css.MediaType = Rendering.MediaType.Screen;
     // Convert HTML to JPG
     Aspose.Html.Converters.Converter.ConvertHTML(document, options, "output.jpg");
}

The issues you have found earlier (filed as HTMLNET-5162) have been fixed in this update. This message was posted using Bugs notification tool by avpavlysh