Hello, we are trying to convert an incoming msg file to pdf. We are using aspose-email 23.8 and aspose-words 23.8. We have two questions:
If an incoming email has a wide image or table, the wide part gets cut off. Is there a way to ensure that the email size is scaled to the resulting PDF correctly?
While we have mostly been successful in retaining the original formatting of the email, occasionally attributes can be lost. Is there a specific setting in aspose that has to be enabled to ensure the email (1) fits to the target pdf page size and (2) retains all data in it?
Aspose.Email.MailMessage msg = Aspose.Email.MailMessage.Load(@"C:\Temp\in.msg");
msg.Save(@"C:\Temp\tmp.mhtml", Aspose.Email.SaveOptions.DefaultMhtml);
Document doc = new Document(@"C:\Temp\tmp.mhtml");
doc.FirstSection.PageSetup.Orientation = Orientation.Landscape;
// Determine the maximum table width using LayoutEnumerator.
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);
double maxTableWidth = 0;
foreach (Section s in doc.Sections)
{
foreach (Table t in s.Body.Tables)
{
enumerator.Current = collector.GetEntity(t.FirstRow.FirstCell.FirstParagraph);
while (enumerator.Type != LayoutEntityType.Row)
enumerator.MoveParent();
maxTableWidth = System.Math.Max(maxTableWidth, enumerator.Rectangle.Width);
}
}
PageSetup ps = doc.FirstSection.PageSetup;
double pageWidth = ps.PageWidth - ps.LeftMargin - ps.RightMargin;
if (pageWidth < maxTableWidth)
ps.PageWidth = maxTableWidth + ps.LeftMargin + ps.RightMargin;
// Update page layout is required since LayoutCollector and LayoutEnumerator were used.
doc.UpdatePageLayout();
doc.Save(@"C:\Temp\out.pdf");
With images the things is even simple, since you can get shape width without building document layout. But if you like, you can use the similar approach.
Also, for context the wide image in the email is still being cut off. Is there a way I can resize images in the document to fit to the page with this method? I have attached the image here. wideImageInEmail.zip (1.3 MB)
Thank you so much @alexey.noskov. Follow up question - when we convert an email with attachments, those attachments tend to be shrunk down to be non recognizable. Is there a way that we can retain the original size of the attachment and/or fit it within the page?
@drymers Could you please attach the problematic input MSG file and output PDF produced on your side? We will check the issue and provide you more information.