Detect Invisible Content in Headers Footers of Word DOC Document using Java | Find Paragraphs in any Type of Headers Footers

Hi am having issues with this file, its look empty, i cant find any content, but i can still fetch shape that has a lot of text? Can you please help me figure this out?
source_Engl.zip (124.8 KB)
code:
Document wordDoc = new Document(“Source_Engl.docx”);
Shape shape = (Shape) wordDoc.getChild(NodeType.SHAPE, 1, true);
System.out.println(shape.getText());

Can you also provide side administartor mail. I got locked on my main account.

Thanks

@sarke,

  1. Please open this document with MS Word
  2. Double click inside Header or Footer area
  3. Tick mark (Enable) this option:
    Header & Footer Tools > Design > Options > Different First Page
  4. Now, you will see that particular content appears inside First Page Header and Footer

Hope, this helps.

Hi, thanks. Thats it.

Is there a way in aspose words to differentiate between, in this case, two footers/paragraphs?
Can i know if some text comes from different first page? @awais.hafeez

@sarke,

The following Java code will identify the Paragraphs in any type of Headers Footers in Word Document:

Document doc = new Document("E:\\Temp\\source_Engl\\source_Engl.docx");

for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
    String text = para.toString(SaveFormat.TEXT).trim();

    if (!text.equals("")) {
        HeaderFooter hf = (HeaderFooter) para.getAncestor(NodeType.HEADER_FOOTER);
        if (hf != null) {
            System.out.println(HeaderFooterType.getName(hf.getHeaderFooterType()) +
                    " contains --> " + text);
        } else {
            System.out.println("Not inside Header Footer Story");
        }
    }
} 

Hope, this helps in achieving what you are looking for.

@awais.hafeez If i got it right this is not 100% reliable, because we can have exactly the same paragraph in regular text and in footer. So this wont work. Is there a way to know for sure?

@sarke,

The Java code that I shared earlier identifies all non-empty Paragraphs which are inside the ‘Headers and Footers’ Story of Word Document.

Unfortunately, your current question is not clear enough therefore we request you to please elaborate your inquiry further by providing the complete details of your usecase. This will help us to understand your scenario, and we will be in a better position to address your concerns accordingly.

Am sorry,my bad, its all clear. Thank you @awais.hafeez

@awais.hafeez I have one more question
Lets say for example, now i have paragraph and i know that his HEADER_FOOTER is type FOOTER_FIRST
But can i know which footer type is set to show on that page that has that paragraph?

@sarke,

Please ZIP and upload a sample Word document and a screenshot highlighting the problematic area here for testing. Please also provide the desired output that you want Aspose.Words to return in this case. We will then investigate the scenario further on our end and provide you more information.