MailMessage mailMsg = MailMessage.Load("About Aspose-1.msg");MemoryStream ms = new MemoryStream();
//Save as MHTML
mailMsg.Save(ms, Aspose.Email.Mail.SaveOptions.DefaultMhtml);//create an instance of LoadOptions and set the LoadFormat to Mhtml
var loadOptions = new Aspose.Words.LoadOptions();
loadOptions.LoadFormat = LoadFormat.Mhtml;//create an instance of Document and load the MTHML from MemoryStream
var document = new Aspose.Words.Document(ms, loadOptions);//create an instance of HtmlSaveOptions and set the SaveFormat to Html
var saveOptions = new Aspose.Words.Saving.PdfSaveOptions();//save the document to Html file
document.Save(“About Aspose.pdf”, saveOptions);
Hi Lee,
Hi Lee,
Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. If you load the intermediate MHTML output generated by Aspose.Email in MS Word and convert it to Pdf, you will get the same output. The table is rendered outside the page in output Pdf. This issue can be resolved using one of following solutions.
- Set the page orientation to landscape.
- Increase the page width.
- Use Table.AutoFit method with AutoFitToWindow behavior to resize the table and cells.
//create an instance of LoadOptions and set the LoadFormat to Mhtml
var loadOptions = new Aspose.Words.LoadOptions();
loadOptions.LoadFormat = LoadFormat.Mhtml;
var document = new Aspose.Words.Document(MyDir + "input.mhtml", loadOptions);
//Solution 1
document.FirstSection.PageSetup.Orientation = Orientation.Landscape;
//Solution 2
//foreach (Table table in document.GetChildNodes(NodeType.Table, true))
// table.AutoFit(AutoFitBehavior.AutoFitToWindow);
//Solutoin 3
//document.FirstSection.PageSetup.PageWidth = 800;
//create an instance of HtmlSaveOptions and set the SaveFormat to Html
var saveOptions = new Aspose.Words.Saving.PdfSaveOptions();
//save the document to pdf file
document.Save(MyDir + "Out.pdf", saveOptions);