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

Free Support Forum - aspose.com

Getting Tables to Orient in Landscape

Hi,
When converting an email (MSG) to pdf via Aspose.Words in landscape orientation, tables in the email do not render in landscape. Here' the code I'm using.

MemoryStream stream = new MemoryStream();
asposeMail.Save(stream, mhtSaveOptions);

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

Document asposeDoc = new Document(stream, loadOptions);
Aspose.Words.Saving.SaveOptions asposeOptions = Aspose.Words.Saving.SaveOptions.CreateSaveOptions(SaveFormat.Pdf);
asposeOptions.PrettyFormat = true;

if (Landscape)
{
for (int i = 0; i < asposeDoc.Sections.Count; i++)
{
asposeDoc.Sections[i].PageSetup.Orientation = Orientation.Landscape;
}
}

asposeDoc.Save(Target, asposeOptions);

stream.Close();
stream.Dispose();

What more would I have to do with the tables to get them to orient to landscape?

Thanks

Hi Rick,


Thanks for your inquiry. Please call Document.UpdatePageLayout method before saving the document to Pdf. Hope this helps you.

If you still face problem, please attach your input MSG file along with output Pdf here for testing? We will investigate the issue on our side and provide you more information.

Thanks for getting back to me so quick. UpdatePageLayout didn’t solve the issue so I’m attaching files.

I tried this from http://www.aspose.com/docs/display/wordsnet/Fitting+all+Tables+to+Page+Width

foreach (Aspose.Words.Tables.Table table in asposeDoc.GetChildNodes(NodeType.Table, true))
{
table.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(100);
}

but the result was no different. It's like the table is being set to portrait before/as the email is being saved to stream, so that it's already too late for the word doc from the stream to effect the table's layout.
Hi Rick,

Thanks for sharing the detail. We have tested the scenario using latest version of Aspose.Words for .NET 17.1.0 with following code example and have not found any issue with output Pdf. Please use Aspose.Words for .NET 17.1.0. We have attached the output Pdf with this post for your kind reference.

Aspose.Email.Mail.MailMessage msg = Aspose.Email.Mail.MailMessage.Load(MyDir + "Test Table.msg");

MemoryStream StreamMHT = new MemoryStream();

msg.Save(StreamMHT);

StreamMHT.Position = 0;

Aspose.Words.LoadOptions lLoadOptions = new Aspose.Words.LoadOptions();

lLoadOptions.LoadFormat = Aspose.Words.LoadFormat.Mhtml;

Document asposeDoc = new Document(StreamMHT, lLoadOptions);

Aspose.Words.Saving.SaveOptions asposeOptions = Aspose.Words.Saving.SaveOptions.CreateSaveOptions(SaveFormat.Pdf);

asposeOptions.PrettyFormat = true;

if (true)

{

for (int i = 0; i < asposeDoc.Sections.Count; i++)

{

asposeDoc.Sections[i].PageSetup.Orientation = Orientation.Landscape;

}

}

foreach (Aspose.Words.Tables.Table table in asposeDoc.GetChildNodes(NodeType.Table, true))

{

table.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(100);

}

asposeDoc.UpdateTableLayout();

asposeDoc.UpdatePageLayout();

asposeDoc.Save(MyDir + "out v17.1.0.pdf");

Thank you so much. UpdateTableLayout() did the trick.

Hi Rick,

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