Reputation: 33
I'm trying to create an Outlook addin that would take the contents of the currently open email, and save it as a word document. Before saving, it should adjust the sizes of picture, tables etc to fit the page width.
I'm strugling with the resizing part.
After fetching the content of the email as a word document object...
var ispector = e.Control.Context as Inspector;
var mailItem = ispector.CurrentItem as MailItem;
var document = ispector.WordEditor as Microsoft.Office.Interop.Word.Document;
... and getting the available width
float availableWidth = document.PageSetup.PageWidth - document.PageSetup.LeftMargin - document.PageSetup.RightMargin;
... I'm iterating through shapes, inline shapes and tables to adjust the width.
foreach (InlineShape item in document.InlineShapes)
{
if (item.Width > availableWidth)
item.Width = availableWidth;
}
foreach (Microsoft.Office.Interop.Word.Table table in document.Tables)
{
table.AllowAutoFit = true;
table.AutoFitBehavior(Microsoft.Office.Interop.Word.WdAutoFitBehavior.wdAutoFitContent);
}
But no matter what I do, the pictures in the saved document are not resized.
I even tried to call a Delete method on every shape/inlineshape but still nothing changes in the saved document.
Any ideas ?
Upvotes: 1
Views: 688
Reputation: 25663
Save the Email as a Word document, first. Open that and apply the formatting to the pictures.
Upvotes: 1