Extract the footnote of the first section and insert that footnote in second section

Hi,
Here is my requirement: I need to get the footnote defined in the first section and append that footnote in the second section.
Here are the structures of my documents: (Please refer to the attachment for details)

  1. there are 2 sections. Why there are 2 sections ? because i need to define different footer between section 1 & section 2.
  2. There is a predefined footer in the 1st section which is also defined as first page.
  3. I need to get that footer in 1st section and copies them into all the footer into 2nd section regardless whether it’s even or odd pages.
    Please refer to my code snippet below :
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToSection(0);
builder.MoveToHeaderFooter(HeaderFooterType.FooterFirst);
Shape[] omrLine = new Shape[10];
for (int i = 0; i < 9; i++)
{
    omrLine[i] = new Shape(doc, ShapeType.Line);
    omrLine[i].Rotation = 90;
    omrLine[i].Top = -10;
    omrLine[i].Left = 10 + (i * 10);
    omrLine[i].Width = 12;
    omrLine[i].StrokeColor = Color.Red;
    omrLine[i].WrapType = WrapType.None;
    omrLine[i].BehindText = true;
    builder.InsertNode(omrLine[i]);
}
builder.MoveToSection(1);
builder.MoveToHeaderFooter(HeaderFooterType.FooterEven);
builder.PageSetup.DifferentFirstPageHeaderFooter = true;
builder.PageSetup.OddAndEvenPagesHeaderFooter = true;
Shape[] omrLine2 = new Shape[10];
for (int i = 0; i < 9; i++)
{
    omrLine2[i] = new Shape(doc, ShapeType.Line);
    omrLine2[i].Rotation = 90;
    omrLine2[i].Top = -10;
    omrLine2[i].Left = i * 10;
    omrLine2[i].Width = 12;
    omrLine2[i].StrokeColor = Color.Green;
    omrLine2[i].WrapType = WrapType.None;
    omrLine2[i].BehindText = true;
    builder.InsertNode(omrLine2[i]);
}

Let me know if my requirements are not clear enough.
Regards,
hadi teo

Hi,
I have performed some modifications to my code. Here is the latest code snippet that i am using

private Document DrawOMRLines(Document doc)
{
    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.MoveToSection(0);

    builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);

    // Node footerInFirstPage = builder.CurrentNode;
    Paragraph footerInFirstPage = builder.CurrentParagraph;

    builder.MoveToHeaderFooter(HeaderFooterType.FooterFirst);
    Shape[] omrLine = new Shape[10];
    for (int i = 0; i < 9; i++)
    {
        omrLine[i] = new Shape(doc, ShapeType.Line);
        omrLine[i].Rotation = 90;
        omrLine[i].Top = -10;
        omrLine[i].Left = 10 + (i * 10);
        omrLine[i].Width = 12;
        omrLine[i].StrokeColor = Color.Red;
        omrLine[i].WrapType = WrapType.None;
        omrLine[i].BehindText = true;
        builder.InsertNode(omrLine[i]);
    }
    builder.MoveToSection(1);
    builder.MoveToHeaderFooter(HeaderFooterType.FooterEven);
    builder.PageSetup.DifferentFirstPageHeaderFooter = true;
    builder.PageSetup.OddAndEvenPagesHeaderFooter = true;
    Shape[] omrLine2 = new Shape[10];
    for (int i = 0; i < 9; i++)
    {
        omrLine2[i] = new Shape(doc, ShapeType.Line);
        omrLine2[i].Rotation = 90;
        omrLine2[i].Top = -10;
        omrLine2[i].Left = i * 10;
        omrLine2[i].Width = 12;
        omrLine2[i].StrokeColor = Color.Green;
        omrLine2[i].WrapType = WrapType.None;
        omrLine2[i].BehindText = true;
        builder.InsertNode(omrLine2[i]);
    }
    builder.MoveToSection(1);
    builder.MoveToHeaderFooter(HeaderFooterType.FooterEven);

    builder.CurrentParagraph.ParentNode.InsertBefore(footerInFirstPage, builder.CurrentParagraph);

    builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
    builder.CurrentParagraph.ParentNode.InsertAfter(footerInFirstPage, builder.CurrentParagraph);

    return doc;

}

Please also refer to the screenshot (screenshot2.docx) that i have attached in this reply.
Even though i have positioned the documentbuilder to FooterEven of the Section[1] and insert the paragraph, it cannot able to insert them correctly.
Regards,
hadi teo

Hi,
I have attached the expected result of the document inside the ‘screenshot3.docx’
Regards,
hadi teo

Hi Hadi,

Thanks for your inquiry. Please see the following code snippet for your kind reference. This code example get the FootNotes of First section and insert them to last section of document. I have attached the input and output document with this post.

Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// Get the Foot notes of first section
NodeCollection notes = doc.Sections[0].GetChildNodes(NodeType.Footnote, true);
// Get the second paragrpah of last section
Paragraph para = (Paragraph)doc.LastSection.GetChild(NodeType.Paragraph, 1, true);
// Move cursor to second paragraph of last section
builder.MoveTo(para);
// insert foot notes
foreach (Footnote note in notes)
{
    builder.InsertNode(note);
}
doc.Save(MyDir + "AsposeOut.docx");

To append Footnote to the document you can also use InsertAfter or InsertBefore on the paragraph where you want the footnote inserted.

// Get the second paragrpah of last section
Paragraph para = (Paragraph)doc.LastSection.GetChild(NodeType.Paragraph, 1, true);
para.InsertAfter(notes[0], para.LastChild);

Following example shows how to add a footnote to a paragraph in the document.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("Some text is added.");
Footnote footnote = new Footnote(doc, FootnoteType.Footnote);
builder.CurrentParagraph.AppendChild(footnote);
footnote.Paragraphs.Add(new Paragraph(doc));
footnote.FirstParagraph.Runs.Add(new Run(doc, "Footnote text."));

I suggest you to use latest version of Aspose.Words for .NET. Please let us know if you have any more queries.

Hi Tahir,
Thanks very much for your assistance. I have applied your suggestions and now it is working well.
Regards,
hadi teo

Hi Hadi,

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