HeaderFooter Clearing Issue

Hi,
I am working with Aspose.Words dll version 14.3.0.0. I am using a piece of code wherein There are 4 sections. Section 1 and 3 have some data in them for which the headerfooter information has to cleared in them. When I do so the footer information of Section 4 is also getting cleared.
Please help on the issue.
Also ther Footer from Section 2-4 have Same As previous property.
Please help on the issue.

Hi,
I am working with Aspose.Words dll version. I am using a piece of code wherein There are 4 sections. Section 1 and 3 have some data in them for which the headerfooter information has to cleared in them. When I do so the footer information of Section 4 is also getting cleared.
Please help on the issue.
Also ther Footer from Section 2-4 have Same As previous property.

Hi there,

Thanks for your inquiry. It would be great if you please share following detail for investigation purposes.

  • Please attach your input Word document.
  • Please

create a standalone/runnable simple application (for example a Console
Application Project
) that demonstrates the code (Aspose.Words code) you used to generate
your output document

  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

Unfortunately,
it is difficult to say what the problem is without the Document(s) and
simplified application. We need your Document(s) and simple project to
reproduce the problem. As soon as you get these pieces of information to
us we’ll start our investigation into your issue.

Hi Tahir,
There are 4 files in the zipped attachment.

  1. Input document
  2. Expected Output document
  3. Actual Output document. The one we get after code execution
  4. Code for the method executed.
    In place of 1e and 2e a data page will come. Similarly in place of 3e and 4e a data page will come. All pages except for this data page will have the footer text. But the footer text in the last section (4th) gets removed, when we clear footer in the previous section (3rd). Thus that is the issue.

Hi there,

Thanks for sharing the detail. Your input document have two sections. The second section has no header/footer and is linked to previous header/footer. See the attached image for detail.

In your case, I suggest you please copy the HeaderFooter from first section into second section. See the following code example for your kind reference.

Document mainDoc = new Document(MyDir + "input.rtf");
foreach (Section section in mainDoc.Sections)
{
    CopyHeadersFootersFromPreviousSection(section);
}
// Your code....
// Your code....
// Your code....
mainDoc.Save(MyDir + "Out.rtf");
private static void CopyHeadersFootersFromPreviousSection(Section section)
{
    Section PreviousSection = (Section)section.PreviousSibling;
    if (PreviousSection == null)
        return;
    if (section.HeadersFooters.Count > 0)
        return;
    section.HeadersFooters.Clear();
    foreach (HeaderFooter headerFooter in PreviousSection.HeadersFooters)
        section.HeadersFooters.Add(headerFooter.Clone(true));
}

Hi,
There are two sections in the document. Section 1 has footer text. Section 2 has the same footer text but Linked to previous.
After the processing, as I had attached, the output document will have 4 sections.
Section 1 will be a new data page without any footer.
Section 2 will thw original document’s Section 1, thus will retain the footer text.
Section 3 will again be a data page without any footer
Section 4 will be input document’s section 2, thus will retain the footer text.
But this is not the case. When I try to delete the footer from section 3, footer text of section 4 is also getting cleared. The code is same as I had attached.
The response you gave says that “The second section has no header/footer and is linked to previous header/footer. See the attached image for detail.”
But if you see the attached image the section 2 had footer text linked to previous.

Also,
In section 2 and in section 1 of the input document, the footer text can be different too…so copying the text fromprevious section will not help.
Also there might be more than 2…upto 136 sections in the input document, so the code needs to be generic.
Please help
Thanks.

Hi there,

Thanks for your inquiry. Please
create a standalone/runnable simple application (for example a Console
Application Project
) that demonstrates the code (Aspose.Words code) you used to generate
your output document (Actual Output.doc).

We will investigate the issue and provide you more information about your query along with code.

I have already provided the code I used as an attachment.
Attaching it again.

Hi there,

Thanks for sharing the detail. I checked this code but this does not produce the ‘Actual Output.doc’. Moreover, the method CheckSectionFootersBeforeComplete is also missing. Please check the following highlighted code.

Please
create a standalone/runnable simple application that demonstrates the code you used to generate
your output document (Actual Output.doc) which contains the DATA pages.

public static void Ce(Aspose.Words.Document mainDoc)
{
    int k = 1;
    bool isloopAll = true;
    foreach (Section sec in mainDoc.Sections)
    {
        Range range = sec.Range;
        if (range.Text.ToLower().Contains("e"))
        {
            if (range.Text.ToLower().Contains("e"))
            {
                sec.HeadersFooters.LinkToPrevious(false);
                sec.HeadersFooters.Clear();
                mainDoc.Save(@"dumbo.doc");
            }
        }
        if (range.Text != string.Empty)
        {
            string pageChar = ControlChar.SectionBreak;
            string resultTxt = range.Text;
            if (resultTxt.Replace(pageChar, "").Replace(ControlChar.ParagraphBreakChar.ToString(), "") == string.Empty && sec.ParentNode != null)
            {
                sec.Remove();
                mainDoc.Save(@"dumbo.doc");
                isloopAll = false;
            }
        }
        else
        {
            if (sec.ParentNode != null)
            {
                sec.Remove();
                mainDoc.Save(@"C:\Users\Pranay_Arya\Desktop\dumbo.doc");
                isloopAll = false;
            }
        }
    }
    if (!isloopAll)
        CheckSectionFootersBeforeComplete(mainDoc);
    else
        return;
}

Hi,
Please find the application as attached.

Hi there,

Thanks for sharing the code. I have worked with your code and expected output document and have found that you want header/footer only for sections of Input.doc. You do not want header/footer for sections of BookCover.doc.

I have modified the shared code according to your requirements. Please check the attached output document code. Hope this helps you.