Insert Shape in Header Footer of Landscape Pages in Word Document C# .NET

@awais.hafeez
How we can insert the same shape in the header and footer of the landscape pages

Thank you very much

@lssupport,

Please check the following C# code of Aspose.Words for .NET API to insert the same Shapes/Images inside the primary headers and footers of all Sections in Word document having Landscape orientation.

Document doc = new Document("C:\\Temp\\input.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

for(int i = 0; i< doc.Sections.Count; i++)
{
    Section section = doc.Sections[i];
    if (section.PageSetup.Orientation == Orientation.Landscape)
    {
        builder.MoveToSection(i);
        builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

        Shape shape = builder.InsertShape(ShapeType.Rectangle, 72, 72);
        Shape cloneOfShape = (Shape) shape.Clone(true);

        builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
        builder.InsertNode(cloneOfShape);
    }
}

doc.Save("C:\\temp\\21.4.docx");
1 Like