i’m having a problem converting an msg file to pdf file. Specifically i have a matrix that should be resized and fit in the pdf file, but after the conversion i can see only a part of it.
public int AsposeEmailConvertToPdf(string inputFile, string outputFile)
{
int ret = 0;
try
{
Aspose.Email.MailMessage mailMsg = Aspose.Email.MailMessage.Load(inputFile);
MemoryStream ms = new MemoryStream();
mailMsg.Save(ms, Aspose.Email.SaveOptions.DefaultMhtml);
Aspose.Words.LoadOptions loadOptions = new Aspose.Words.LoadOptions();
loadOptions.LoadFormat = Aspose.Words.LoadFormat.Mhtml;
Aspose.Words.Document document = new Aspose.Words.Document(ms, loadOptions);
Aspose.Words.Saving.PdfSaveOptions saveOptions = new Aspose.Words.Saving.PdfSaveOptions();
document.Save(outputFile, saveOptions);
You can see that the problematic Table in this MHTML is wider than the standard Page width of MS Word documents (i.e. 8.5 inches). You can check this by opening this MHtML with MS Word 2019. So, this is an expected behavior.
However, there are a few ways that you can use to workaround this problem:
Increase PDF page Width
Adjust / Decrease widths of Tables so that it fits inside existing PDF Pages
Auto fit Tables to Windows etc
C# Draft Code:
Aspose.Email.MailMessage mailMsg = Aspose.Email.MailMessage.Load("E:\\Temp\\0001cjln.1.msg\\0001cjln.1.msg");
mailMsg.Save("E:\\Temp\\0001cjln.1.msg\\0001cjln.1.mhtml", Aspose.Email.SaveOptions.DefaultMhtml);
Aspose.Words.LoadOptions loadOptions = new Aspose.Words.LoadOptions();
loadOptions.LoadFormat = Aspose.Words.LoadFormat.Mhtml;
Aspose.Words.Document document = new Aspose.Words.Document("E:\\Temp\\0001cjln.1.msg\\0001cjln.1.mhtml", loadOptions);
//foreach (Table tbl in document.GetChildNodes(NodeType.Table, true))
//{
// set tables width manually e.g.
//double tblWidth = document.FirstSection.PageSetup.PageWidth - document.FirstSection.PageSetup.LeftMargin - document.FirstSection.PageSetup.RightMargin;
//tbl.PreferredWidth = PreferredWidth.FromPoints(tblWidth);
// or AutoFit Tables To Window
//tbl.AllowAutoFit = true;
//tbl.AutoFit(AutoFitBehavior.AutoFitToWindow);
//}
// Or increase Page width
document.FirstSection.PageSetup.PaperSize = Aspose.Words.PaperSize.Ledger;
//document.FirstSection.PageSetup.Orientation = Orientation.Landscape;
Aspose.Words.Saving.PdfSaveOptions saveOptions = new Aspose.Words.Saving.PdfSaveOptions();
document.Save("E:\\Temp\\0001cjln.1.msg\\20.2.pdf", saveOptions);
Hope, this helps in achieving what you are looking for.