Section.HeadersFooters returns null for first header and footer using Java

Good afternoon!

When processing a Word-format document, the footers on the first and second pages of the document are not processed correctly:
Source document:

  1. On page 1 there are headers and footers that have the property “Special footer for the first page”
  2. On page 2 there are the default header and footer, which contain tables.

After processing the document with Aspose.Words for Java:

  1. When you run the code to retrieve data from the header of the second page (“doc.getSections (). Get (1) .getHeadersFooters (). Get (0) .getText ()”) Aspose.Words for Java returns an empty header (" \ r “) (as if it is a footer with the property” Special footer for the first page "). If you take the data from the first page, then the footer will return from the second page (in the original document).

  2. When you run the code to retrieve data from the footer of the second page (“doc.getSections (). Get (1) .getHeadersFooters (). Get (1) .getText ()”) Aspose.Words for Java returns the doubled information:

© XX «XXX-xxxxxxxxxx» XXX «XXXXXXXXX-x» PAGE * MERGEFORMAT xx / NUMPAGES * MERGEFORMAT xx © XX «XXX-xxxxxxxxxx» XXX «XXXXXXXXX-x» PAGE * MERGEFORMAT xx / NUMPAGES * MERGEFORMAT xx

Source file: Example.zip (114.4 KB)

Please consult us, what are the problems associated with and how can they be solved?

@beralex

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Please attach the output that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a simple Java application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

@tahir.manzoor,

Good afternoon!

We apply the Java mini-application (written in Java 11, AsposeHeaderFooterDemoProject.zip (1.9 MB)). The code describes the current behavior (AS IS) and the desired behavior:

  1. In the document “nullHeaderFooterFirst.docx” on the first page (in the first section) there are headers and footers that have the property “Special footer on the first page”. But when requesting headers and footers, null is returned (although they are actually present).
    Purpose: We need from the first page (first section) to get a header with the property “Special header for the first page”.
    Question: How to solve this problem?
  2. In the document “wanderingHeaderFooter.doc” on the first page (in the first section) there is a header having the property “Special header on the first page”; on the second page (second section) there is a default header. But:
  • When requesting a header from the first page (first section), a default header is returned.
  • When requesting a header from the second page (second section), the header with the property “Special header for the first page” is returned.
    Purpose: We need from the first page (first section) to get a header with the property “Special footer for the first page”, from the second page (second section) - a default header (as implemented in the document).
    Question: How to solve this problem?
  1. In the document “TwiceTextFooter.doc” on the second page (second section) there is a default footer. But when querying the contents of the footer, the text is returned twice.
    Purpose: We need to get the contents of the default footer from the second page (second section) once (as implemented in the document), and not 2 times.
    Question: How to solve this problem?

@beralex

We are working over your query and will get back to you soon.

@beralex

We have logged this issue as WORDSNET-19943 in our issue tracking system.

We have logged this issue as WORDSNET-19944 in our issue tracking system.

We have logged this issue as WORDSNET-19945 in our issue tracking system.

You will be notified via this forum thread once these issues are resolved. We apologize for your inconvenience.

@tahir.manzoor
Good day!
How are things going in the analysis of the problem described in the messages above? We are waiting for a solution, because because of this, the development of the project was stopped.

@beralex

Unfortunately, there is no ETA available for WORDSNET-19943 and WORDSNET-19944 at the moment. We will inform you via this forum thread once there is an update available on these issues.

Regarding WORDSNET-19945 (HeadersFooter.GetText returns the text twice), you are facing the expected behavior of Aspose.Words. There are actually two different footers with the same text in the document. Please search the same text in MS Word to check it. Moreover, please check the attached images for issue detail.

19945_1.png (38.3 KB)
19945_2.png (49.0 KB)
19945_3.png (54.6 KB)

@beralex

It is to inform you that the issues WORDSNET-19943 and WORDSNET-19944 are not bugs in Aspose.Words. So, we have closed these issues.

The headers and footers you wants to get from the documents do not exists in the shared documents.

Please note that Aspose.Words code represents the Document internal structure, not how the document looks like in MS Word editor. Each section can contain three different types of headers: First page header, Odd page header and Even page header. In Aspose.Words these are HeaderFooterType.HeaderFirst, HeaderFooterType.HeaderPrimary and HeaderFooterType.HeaderEven respectively.