MHT to PDF conversion - wide tables are cropped

We are using Aspose to convert emails to PDFs, via intermediate MHT files.

Using
Aspose.Words for .NET 14.2 we have noticed that in some cases with highly indented email threads or wide tables, the contents of the email (ie. the contents of the MHT file) disappears off the side of the PDF.

This is the code we use to generate PDFs from MHTs:

var doc = new Document(mhtInputPath);
doc.Save(pdfOutputPath, new Aspose.Words.Saving.PdfSaveOptions());

I have attached a sample MSG, MHT and PDF.

Is there any way to automatically scale the content to fit the width of the PDF page?

Thanks,

Reuben

Hi Reuben,

Thanks for your inquiry. In your case, I suggest you please increase the page width of document. Please use the following code snippet to get the required output.

Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "in.mht");
foreach(Section section in doc.Sections)
{
    // section.PageSetup.Orientation = Aspose.Words.Orientation.Landscape;
    section.PageSetup.PageWidth = 1200;
}
doc.Save(MyDir + "Out.pdf");

Hi Tahir,

Thanks for your reply. We require the PDF to be A4 sized. Is there any way to scale the pages to fit within the width of an A4 page?

Regards,

Reuben

Hi Reuben,
You can replace the PageWidth with PaperSize in the above mentioned code e.g.

section.PageSetup.PaperSize = PaperSize.A4;

Best Regards,

Thanks. Actually we’re already doing that.

The content of the MHT is wider than an A4 page. Is there any way to scale it to less than 100% of the original size so it fits on the page?

Regards,

Reuben

Hi Reuben,

Thanks for your inquiry. The contents of your input MHTML file are inside tables. Please use the PreferredWidth.FromPoints method to set the width of table’s value as shown in following code snippet to get the required output. I have attached the output Pdf file with this post for your kind reference.

Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "in.mht");
foreach(Table table in doc.GetChildNodes(NodeType.Table, true))
{
    table.PreferredWidth = PreferredWidth.FromPercent(100);
}
doc.Save(MyDir + "Out.pdf");

This solution works well. Thanks.

Hi Reuben,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.