We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Table in MHTML is rendered outside the page in converted PDF

Hi, the body of the attached message is not fully converted to PDF, see the attached result PDF. I also included the generated mhtml file. I tested this with te latest version of Aspose.Mail and Aspose.Word.

Claim Boogaard.zip (496.0 KB)

This is the code we use:

MemoryStream stream = new MemoryStream();

MhtSaveOptions opt = Aspose.Email.SaveOptions.DefaultMhtml;
opt.SaveAttachments = false;
theMessage.Save(stream, opt);

string htmlFileName = Path.Combine(outputPath, Path.ChangeExtension(Path.GetFileName(inputFileName), ".mhtml"));
theMessage.Save(htmlFileName, opt);

stream.Seek(0, SeekOrigin.Begin);

Aspose.Words.LoadOptions loadOptions = new Aspose.Words.LoadOptions();
loadOptions.LoadFormat = Aspose.Words.LoadFormat.Mhtml;

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

Aspose.Words.Document doc = new Aspose.Words.Document(inputFileName, stream, loadOptions);

doc.UpdateTableLayout();

PageSetup ps = doc.FirstSection.PageSetup;
double effectiveWidth = ps.PageWidth - (ps.LeftMargin + ps.RightMargin);

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Shape shape in shapes)
	shape.Width = (shape.Width > effectiveWidth) ? effectiveWidth : shape.Width;

Aspose.Words.Saving.PdfSaveOptions options = new Aspose.Words.Saving.PdfSaveOptions();
options.Compliance = PdfCompliance.Pdf15;

string outputFileName = Path.Combine(outputPath, Path.ChangeExtension(Path.GetFileName(inputFileName), ".pdf"));

doc.Save(outputFileName, options);

@andreas4e47b

Please set the table’s width as shown below to get the desired output.

foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
{
    table.PreferredWidth = PreferredWidth.FromPercent(100);
    table.LeftIndent = 0;
}

doc.UpdatePageLayout();
doc.Save(MyDir + "19.12.pdf", options);