Interop.Word HeaderFooter Shapes.AddPicture (Default Anchor Problem)

Terminader 0 Reputation points
2023-03-08T17:48:08.15+00:00

Dear community,

I noticed that MS Word has a different anchoring when we add an image to a page footer using Interop.

The anchoring position depends on the HeaderFooterIndex (See below results)

Example: Insert shape to header

Section section = ...;
section.Headers[VarHeaderFooterIndex].Shapes.AddPicture(FileName: fileName, Left: 0, Top: 0);
// The result depending on 'VarHeaderFooterIndex' value is:
// wdHeaderFooterPrimary -> Shape will be anchored to header (ok)
// wdHeaderFooterFirstPage -> Shape will be anchored to header (ok)
// wdHeaderFooterEvenPages -> Shape will be anchored to header (ok)

Example: Insert shape to footer

Section section = ...;
section.Footers[VarHeaderFooterIndex].Shapes.AddPicture(FileName: fileName, Left: 0, Top: 0);

// The result depending on 'VarHeaderFooterIndex' value is:
// wdHeaderFooterPrimary -> Shape will be anchored to footer(ok)
// wdHeaderFooterFirstPage -> Shape will be anchored to header (not ok)
// wdHeaderFooterEvenPages -> Shape will be anchored to header (not ok)
Microsoft 365 and Office | Development | Other
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.