Free Support Forum - aspose.com

Footers order

Hi,


Attached file has a two footers. Ordering of footer in Aspose.Words is not good, when you execute following code you can see that the first footer is from the second page and then the footer from the first page.
code:
"String path = “footer.doc”;
Document document = new Document(path);
HeaderFooterCollection footerCollection = document.getFirstSection()
.getHeadersFooters();
for (HeaderFooter footer : footerCollection) {
ParagraphCollection paragraphCollection = footer.getParagraphs();
for (Paragraph paragraph : paragraphCollection) {
System.out.println(paragraph.getText());
}
}
"
output:
PAGE A—2
Appendix A—A brief treatise on Eutrophication of Lakes
PAGE A—1
Bioassessment of Freshwaters using Benthic Macroinvertebrates- A Primer

so, this is a problem for me. Can you help me please, why this happens?

Thanks,
Bojan


Hi Bojan,


Thanks for your inquiry. I have worked with your document and like to share with you that this is not an issue. Your document contains one section with two footers FooterEven and FooterPrimary. Please see the attached image.

1) FooterEven : Footer for even numbered pages.
2) FooterPrimary : Primary footer, also used for odd numbered pages.

Please use the following code snippet for your kind reference.


<span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;color:#2B91AF;mso-font-kerning:
0pt;mso-no-proof:yes”>Document<span lang=“EN-GB” style=“font-size:10.0pt;
font-family:“Courier New”;mso-font-kerning:0pt;mso-no-proof:yes”> doc = new Document(MYDir

  • “footer.doc”);<o:p></o:p>

HeaderFooter footerEven = doc.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_EVEN);

for (Paragraph paragraph : footerEven.getParagraphs()) {

System.out.println(paragraph.getText());

}

HeaderFooter footerPrimary = doc.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_PRIMARY);

for (Paragraph paragraph : footerPrimary.getParagraphs()) {

System.out.println(paragraph.getText());

}

Thanks,

but generally, could I know the order of Footers? Because I use the Document.Visitor and will be fine to have the order of Footers as MS Word by page, does it possible?

Hi Bojan,


Thanks for your inquiry. Generally, The HeaderFooter collection returns as follow but it also depends how you add HeaderFooter into a section.

HEADER_EVEN = 0
HEADER_PRIMARY = 1
FOOTER_EVEN = 2
FOOTER_PRIMARY = 3
HEADER_FIRST = 4
FOOTER_FIRST = 5

Please check the following code snippet, The HeaderFooter collection returns the HeaderFooter in the same order in which they are added. In this case, you need to write code by using Switch or IF statement to identify the type of HeaderFooter and write code accordingly. You may also share your scenario with us we will share the code accordingly.

Hope this answers your query. Please let us know if you have any more queries.

<span style=“font-size:10.0pt;
font-family:“Courier New”;color:#2B91AF;mso-font-kerning:0pt;mso-ansi-language:
PL;mso-no-proof:yes”>Document<span style=“font-size:10.0pt;font-family:
“Courier New”;mso-font-kerning:0pt;mso-ansi-language:PL;mso-no-proof:yes”> doc
= new Document();<o:p></o:p>

Section sec = doc.getFirstSection();

HeaderFooter footer = sec.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_FIRST);

if (footer == null)

{

footer = new HeaderFooter(doc, HeaderFooterType.FOOTER_FIRST);

sec.getHeadersFooters().add(footer);

}

footer = sec.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_EVEN);

if (footer == null)

{

footer = new HeaderFooter(doc, HeaderFooterType.FOOTER_EVEN);

sec.getHeadersFooters().add(footer);

}

footer = sec.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_PRIMARY);

if (footer == null)

{

footer = new HeaderFooter(doc, HeaderFooterType.FOOTER_PRIMARY);

sec.getHeadersFooters().add(footer);

}

HeaderFooterCollection headersFooters = sec.getHeadersFooters();

for (HeaderFooter footertype : headersFooters)

{

System.out.println(footertype.getHeaderFooterType());

}

Thanks,


but when I open the .doc file which is create in the MS Word as attached file, can I know which order of HeaderFooter will be in HeaderFooterCollection, that is my question?

Hi Bojan,


Thanks for your inquiry. The Section.getHeadersFooters() return collection in following order.
  1. HEADER_EVEN = 0
  2. HEADER_PRIMARY = 1
  3. FOOTER_EVEN = 2
  4. FOOTER_PRIMARY = 3
  5. HEADER_FIRST = 4
  6. FOOTER_FIRST = 5