Unexpected behavior - header footer

Hi,
I’m seeing the behavior when I save the single paged document while cursor being present in default header (different first, odd and even page headers footers flag disabled).

When detecting headers and footers for the same document Aspose is reporting all 6 different headers and footers are present.

Please see the attached image for reproducing the same scenario. Also attaching such doc in which only default (primary) header footer are present but Aspose reports all 6 are present.


Document doc1 = new Document(“specialDoc.docx”);
System.out.println(doc1.getFirstSection().getHeadersFooters().getCount());
int count = doc1.getFirstSection().getHeadersFooters().getCount();

for(int i = 0; i < count; i++) { System.out.println(doc1.getFirstSection().getHeadersFooters().get(i).getHeaderFooterType());
System.out.println(doc1.getFirstSection().getHeadersFooters().get(i).getText());
}


Hi Praneeth,

Thanks for your inquiry. HeaderFooter class represents a container for the header or footer text of a section. 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. You can add and remove HeaderFooter from a section.

If Section does not have a HeaderFooter of a specific type or the HeaderFooter has no child nodes, this header/footer is considered linked to the header/footer of the same type of the previous section in Microsoft Word. When HeaderFooter contains at least one Paragraph, it is no longer considered linked to previous in Microsoft Word.

PraneethS:
I’m seeing the behavior when I save the single paged document while cursor being present in default header (different first, odd and even page headers footers flag disabled).
Please check the following PageSetup properites. You can set the value of these properties to ture to enable the ‘Differnt First Page’ and ‘Different Odd & Even pages’.

PageSetup.OddAndEvenPagesHeaderFooter Property : True if the document has different headers and footers for odd-numbered and even-numbered pages.

PageSetup.DifferentFirstPageHeaderFooter Property : True if a different header or footer is used on the first page.

The case is I don’t want any header and footer other than the primary in the section in this particular case and don’t want to enable other headers and footers. The question is why they (different {first, even, odd} page X{header, footer}) got created when I save in the way mentioned in my last post in the thread.

Is this a bug?

Hi Praneeth,

Thanks for your inquiry.

PraneethS:
When detecting headers and footers for the same document Aspose is reporting all 6 different headers and footers are present.

Please see the attached image for reproducing the same scenario. Also attaching such doc in which only default (primary) header footer are present but Aspose reports all 6 are present.
The first section of your document t5.docx has header/footer of all types. Please see the attached images for detail.

To confirm, please rename your docx file to t5.zip and open or extract it. Navigate to ‘word’ folder. There you’ll find ‘header1.xml’, ‘header2.xml’, ‘header3.xml’, ‘footer1.xml’, ‘footer2.xml’ and ‘footer3.xml’ (you can verify these header/footer in DocumentExplorer as well).

PraneethS:
I don’t want to enable other headers and footers. The question is why they (different {first, even, odd} page X{header, footer}) got created when I save in the way mentioned in my last post in the thread.

Document doc1 = new Document(“specialDoc.docx”);
System.out.println(doc1.getFirstSection().getHeadersFooters().getCount());
int count = doc1.getFirstSection().getHeadersFooters().getCount();
for(int i = 0; i < count; i++) { System.out.println(doc1.getFirstSection().getHeadersFooters().get(i).getHeaderFooterType());
System.out.println(doc1.getFirstSection().getHeadersFooters().get(i).getText());
}
Aspose.Words does not create the header/footer while getting text or type of header/footer. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v14.1.0) from here and let us know how it goes on your side.

In your code, you are using ‘specialDoc.docx’ and you shared the document t5.docx. If you are not using t5.docx, please share your input document here for testing. I will investigate the issue and provide you more information.