HTML email to pdf conversion: size of inline graphics incorrect

Hi,

i’m trying to convert an HTML email to pdf via the Apose.Email.dll and Aspose.Words.dll.

The function looks like

public static void ConvertHtmlMail2Pdf(string strSourceFN)
{
string strTempFN = Path.GetDirectoryName(strSourceFN) + “\”+ Path.GetFileNameWithoutExtension(strSourceFN) + “.mht”;
string strDestFN = Path.GetDirectoryName(strSourceFN) + “\” + Path.GetFileNameWithoutExtension(strSourceFN) + “.pdf”;

MailMessage mail = MailMessage.Load( strSourceFN);

MhtMessageFormatter mailFormatter = new MhtMessageFormatter();
mailFormatter.FromFormat = "<span class=“headerLineTitle”>Von:<span class=“headerLineText”> {0} "; //Wichtig: korrekte Anführungszeichen " benutzen
mailFormatter.DateTimeFormat = “dd.MM.yyyy HH:mm”;
mailFormatter.SentFormat = “<span class=“headerLineTitle”>Gesendet:<span class=“headerLineText”> {0}
”;
mailFormatter.ToFormat = “<span class=“headerLineTitle”>An:<span class=“headerLineText”> {0}
”;
mailFormatter.SubjectFormat = “<span class=“headerLineTitle”>Betreff:<span class=“headerLineText”> {0}
”;
mailFormatter.BccFormat = “<span class=“headerLineTitle”>Bcc:<span class=“headerLineText”> {0}
”;
mailFormatter.CcFormat = “<span class=“headerLineTitle”>Cc:<span class=“headerLineText”> {0}
”;
mailFormatter.AttachmentFormat = “<span class=“headerLineTitle”>Anlagen:<span class=“headerLineText”> {0}
”;

mailFormatter.Format(mail);

mail.Save(strTempFN, MessageFormat.Mht, MailMessageSaveOptions.None);

LoadOptions loadOpt = new LoadOptions();
loadOpt.LoadFormat = LoadFormat.Mhtml;

Document wordDoc = new Document(strTempFN, loadOpt);

PdfSaveOptions saveOpt = new PdfSaveOptions();
wordDoc.Save(strDestFN, saveOpt);
}

The pdf document shows an incorrect layout. The graphic at the right size is much to big and some graphics are missing.

I’m using Aspose.Email.dll Version 1.9.0.0 and Aspose.Words.11.5.0.0

Internal bugid# 4635

Thanks for help, Martin

Hi Martin,


Thank you for using Apose products as part of your solutions.

The output PDF file is missing the images for the reason that these images are missing in the MHT file that is generated by Aspose.Email v1.9. I tried your code with the latest version Aspose.Email for .NET v 2.0.0 and the MHT file is now generated fine, i.e. none of the images are missing. I have attached the generated MHT file here for your reference.

For your second issue of the right size graphics being rendered too large, I think this has something to do with the rendering of the MHT file to PDF by Aspose.Words. Our Aspose.Words Team can better assist you in this regard. You can contact the Aspose.Words team HERE for further assistance.

Please let us know if we can be of additional help to you. We will be glad to assist you further.

Hi Kashif,

many thanks for your quick response. You’re right the new Aspose.Email.dll 2.0.0.0 shows better results.

I contacted the Aspose.Words team to resolve the remaining issues - see Email in Mhtml format shows disarranged layout when converted to pdf

Best regards, Martin

Hi Martin,


Thanks for providing the feedback.

It’s good to know that half of your problem is resolved now. Please fee free to contact us if you find any other difficulty using Aspose.Email. We will try our best to help you as soon as possible.