Incorrect result when converting eml to image

Hi!

I'm using Aspose.Words (and Aspose.Email) to convert eml documents to images (jpg).

Here is my testing code:

Aspose.Words.Document doc;
var message = MailMessage.Load("AS.eml", MessageFormat.Eml);
message.PreferredTextEncoding = Encoding.UTF8;

using (var mhtStream = new MemoryStream())
{
message.Save(mhtStream, MailMessageSaveType.MHtmlFromat, MailMessageSaveOptions.WriteHeaderToMht);
doc = new Aspose.Words.Document(mhtStream);
}

int pageCount = doc.PageCount;

var imageSaveOptions = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Jpeg);
imageSaveOptions.JpegQuality = 80;
imageSaveOptions.Resolution = 150;
imageSaveOptions.PageCount = 1;

for (int counter = 0; counter < doc.PageCount; counter++)
{
imageSaveOptions.PageIndex = counter;
doc.Save(string.Format("AS_{0}.jpg", counter.ToString()), imageSaveOptions);
}

And generally this works fine. But on the attached eml document the images are not generated correctly. If I use an older version of Aspose.Words (eg. 11.8) the image is correct. So I presume that it's a bug which was produced in the newer versions.

Regards,
Dejan

Hi Dejan,

Thanks for your inquiry. In your case, I suggest you please use the Document’s Constructor (Stream, LoadOptions) with LoadOptions. This constructor opens an existing document from a stream. Allows to specify additional options such as load format of document, an encryption password and baseUri.

Please check the following highlighted code snippet. Hope this helps you. I have attached the output Jpg with this post for your kind reference. Please let us know if you have any more queries.

Aspose.Words.Document doc;

var message = MailMessage.Load(MyDir + “in.eml”, MessageFormat.Eml);

message.PreferredTextEncoding = Encoding.UTF8;

using (var mhtStream = new MemoryStream())

{

message.Save(mhtStream, MailMessageSaveType.MHtmlFormat, MailMessageSaveOptions.WriteHeaderToMht);

doc = new Aspose.Words.Document(mhtStream, new LoadOptions(LoadFormat.Mhtml, “”, “”));

}

int pageCount = doc.PageCount;

var imageSaveOptions = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Jpeg);

imageSaveOptions.JpegQuality = 80;

imageSaveOptions.Resolution = 150;

imageSaveOptions.PageCount = 1;

for (int counter = 0; counter < doc.PageCount; counter++)

{

imageSaveOptions.PageIndex = counter;

doc.Save(MyDir + string.Format(“AS_{0}.jpg”, counter.ToString()), imageSaveOptions);

}

Yes, this helps. Now the image is generated correctly.

Thanks!

Hi Dejan,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.