@kushalpaliwal847
Please note that HeaderFooter is a section-level node and can only be a child of Section. There can only be one HeaderFooter or each HeaderFooterType in a Section. Your document contains only one section. You need to insert section break at second last page of document to insert new section into document. By using this approach, you can achieve your requirement.
Following code example shows how to insert section break at the second last page of document and insert image at the bottom of document. Hope this helps you.
Document doc = new Document(MyDir + "Current Implementation Result.docx");
doc.FirstSection.PageSetup.DifferentFirstPageHeaderFooter = true;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();
int page = doc.PageCount;
LayoutCollector collector = new LayoutCollector(doc);
Node node = builder.CurrentParagraph;
while (node != null)
{
node = node.PreviousPreOrder(doc);
if (node.NodeType == NodeType.Paragraph && collector.GetStartPageIndex(node) == page - 1)
{
node = node.PreviousPreOrder(doc);
builder.MoveTo(node);
builder.InsertBreak(BreakType.SectionBreakContinuous);
break;
}
}
HeaderFooter header = new HeaderFooter(doc, HeaderFooterType.FooterPrimary);
header.IsLinkedToPrevious = false;
doc.LastSection.HeadersFooters.Add(header);
builder.MoveToDocumentEnd();
Shape shape = builder.InsertImage(MyDir + "email_foot (1).png");
shape.Width = doc.LastSection.PageSetup.PageWidth;
shape.WrapType = WrapType.None;
shape.BehindText = true;
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
shape.HorizontalAlignment = HorizontalAlignment.Center;
shape.VerticalAlignment = VerticalAlignment.Bottom;
doc.Save(MyDir + "21.9.docx");