Table is cut off after MSG to PDF conversion

Hi Team, we are having the same issue with the latest Dll. Please advise if you have any solution to it.
we are converting from MSG- > PDF.
Please advise

@RAJASHM Could you please attach your source and problematic output documents here for testing? We will check the issue and provide you more information.

Hi Alexey,
Thank you so much.
MSG to PDF.zip (43.1 KB)
Please find attached.

@RAJASHM The table is simply too wide to fit the page. You can increase page size to get the desired result:

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.PaperSize = Aspose.Words.PaperSize.A3;
doc.FirstSection.PageSetup.Orientation = Orientation.Landscape;
doc.Save(@"C:\Temp\out.pdf");

out.pdf (45.1 KB)

1 Like

image attached to email…jpg (167.6 KB)
Hi @alexey.noskov, Thank you so much for responding. The above solution solves the most of the issues. But Business has come up with a case where if the image size is large then it cut off the image from right.
Please find the attached email as well as the resulted PDF.

Kindly advise if this possible to convert the entire image in Out Look to Pdf irrespective of the image size.
Also please advise what is the maximum height and width of the image/table is supported by aspose to convert the image/table to PDF without cutting it.
A quick response will be highly oblised.
Converted PDF.pdf (1.4 MB)

@RAJASHM The maximum allowed shape width and height in MS Word documents is 1584pt. Aspose.Words uses the same limitation since Aspose.Words is designed to work with MS Word documents at first.
In your case you can adjust shape size so it fit the available page width to avoid image clipping. It would be better if you attach the source document here for testing and code that will allow us to reproduce the problem. We will check the issue and provide you more information.

Hi Alexey,

Thank you.

We are following the below steps to convert an email to PDF

We are following the below steps.

Hi Alexey,

Sincere apologies.

Hi Alexey,
Thank you for your response.
We are following the below steps to convert an email to PDF

  1. Convert the email to Document (through Aspose.Email)
  2. Convert document to PDF( through Aspose.PDF)

attached the document and the code for the same.

Dim ms As MemoryStream = New MemoryStream()
msg.Save(ms, Aspose.Email.SaveOptions.DefaultMhtml)
Dim loadOptions As Aspose.Words.Loading.LoadOptions = New Aspose.Words.Loading.LoadOptions()
loadOptions.LoadFormat = Aspose.Words.LoadFormat.Mhtml
Dim document As Aspose.Words.Document = New Aspose.Words.Document(ms, loadOptions)
                   
document.FirstSection.PageSetup.PaperSize = Aspose.Words.PaperSize.A3
document.FirstSection.PageSetup.Orientation = Orientation.Landscape
                  
Dim saveOptions As Aspose.Words.Saving.PdfSaveOptions = New Aspose.Words.Saving.PdfSaveOptions()
saveOptions.PrettyFormat = True
Dim pdfMS As MemoryStream = New MemoryStream()
document.Save(pdfMS, saveOptions)

RE EXTERNAL Free Support Forum - aspose.com Aspose.Words Product Family Table is cut off after MSG to PDF conversion.zip (1.1 MB)

@RAJASHM You can use the following code to make sure there are no shapes, which size is bigger than the page available space:

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.PaperSize = Aspose.Words.PaperSize.A3;
doc.FirstSection.PageSetup.Orientation = Orientation.Landscape;

// Get avaialble space on the page.
PageSetup ps = doc.FirstSection.PageSetup;
double maxWidth = ps.PageWidth - ps.LeftMargin - ps.RightMargin;
double maxHeight = ps.PageHeight - ps.TopMargin - ps.BottomMargin;

// make sure there are no shapes, whcoh goes outside the page margins.
foreach (Shape s in doc.GetChildNodes(NodeType.Shape, true))
{
    if (!s.IsTopLevel)
        continue;

    if (s.Width > maxWidth)
    {
        s.AspectRatioLocked = true;
        s.Width = maxWidth;
    }
    if (s.Height > maxHeight)
    {
        s.AspectRatioLocked = true;
        s.Height = maxHeight;
    }
}

doc.Save(@"C:\Temp\out.pdf");

Hi @alexey.noskov, Thank you so much. It solves the Image issue like a charm.
Now we come across another issue. If we are copying an Excel of having more than 17 columns it will cut the excel after 15th Column. I have attached the input Email as well as the Out put PDF.
Kindly advise.
Thank you so much for helping.Large table Email Input.zip (24.7 KB)
Large Table cutting Output.pdf (38.9 KB)

@RAJASHM You can try using LayoutCollector and LayoutEnumerator to calculate actual table width and adjust page width accordingly:

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");

Hi @alexey.noskov, Thank you so much. This resolved the Table cut off issue.
However business has reported another issue where the embedded image in .MSG file got cut off from the bottom after it is converted to PDF.
I have attached the input .msg file, Output .pdf file and the Code.

Kindly advise.
Image cut off from Bottom.zip (2.4 MB)

@RAJASHM Unfortunately I cannot reproduce the issue with the code you provided. Here is output generated on my side test.aw238.pdf (320.3 KB). Could you please update to the latest versions of Aspose.Words and Aspose.Email and check it again. If the issue will remain on your side, please create a simple standalone console application which reproduces the issue and attach it here.