Page margins when saving mhtml to jpeg

Hello,


I am converting an email message to JPEG. I have used the MailMessage class from Aspose.Email to save the email to MHTML. The output from that is fine.
I am then loading the MHTML into a Document object from Aspose.Words and saving to JPEG. The output JPEG has huge margins around the edge, which is not what I want. So, I am attempting to reduce the margins, but nothing I do seems to change it.

I have tried playing around with all of the PageSetup properties, but nothing seems to make any difference for the image save:

foreach (var section in doc.Document.OfType())
{
section.PageSetup.Gutter = 0;
section.PageSetup.LeftMargin = 1;
section.PageSetup.TopMargin = 1;
section.PageSetup.RightMargin = 1;
section.PageSetup.BottomMargin = 1;
section.PageSetup.HeaderDistance = 1;
section.PageSetup.FooterDistance = 1;
}

If I save to DOCX format and open in Word, the margins are as I want them. It appears they are ignored when saving to image formats.


Here is a complete code sample:

var loadOptions = new LoadOptions {LoadFormat = LoadFormat.Mhtml};

var doc = new Document(inputStream, loadOptions);
var options = new ImageSaveOptions(SaveFormat.Jpeg)
{
JpegQuality = quality,
PageIndex = 1,
Resolution = dpi,
UseHighQualityRendering = true
};

foreach (var section in doc.Document.OfType())
{
section.PageSetup.Gutter = 0;
section.PageSetup.LeftMargin = 0;
section.PageSetup.TopMargin = 0;
section.PageSetup.RightMargin = 0;
section.PageSetup.BottomMargin = 0;
section.PageSetup.HeaderDistance = 0;
section.PageSetup.FooterDistance = 0;
}

doc.Save(“C:\outputFileName”, options);



How do I reduce the margins when saving to image??

After restructuring my code it now seems to work. Very bizarre behaviour from the Aspose library…

Hi Chris,


Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input email message file.
  • Aspose.Email generated MHTML
  • Aspose.Words generated output document (JPEG files) which shows the undesired behavior.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information.

Best regards,