Page 1 of 1

Issuee with updating header for multipage.docx with a footer

PostPosted: Tue May 24, 2016 10:44 pm
by nishant.singh
I have a requirement to update the header on first page of a .docx file.
This can be achieved using:
SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
headerReference = objectFactory.createHeaderReference();
headerReference.setId(relationship.getId());
headerReference.setType(HdrFtrRef.FIRST);
sectPr.getEGHdrFtrReferences().add(headerReference);

But the above doesn't work unless Title page is set to true.
BooleanDefaultTrue boolanDefaultTrue = new BooleanDefaultTrue();
sectPr.setTitlePg(boolanDefaultTrue);

When the above is done, footer on first page of document is replaced by some junk (perhaps default) footer.
If I set headerReference.setType(HdrFtrRef.DEFAULT), the footer is not replaced but this leads to header on all pages.

Could someone please help me with a solution to update only first page header without disturbing the footer in a word doc with multiple pages.

Thanks.

Re: Issuee with updating header for multipage.docx with a fo

PostPosted: Wed May 25, 2016 12:03 am
by jason
Its a while since I've experimented with headers/footers, but what you report sounds plausible. You could add a first page header in Word and see what it does with the footers...

Why don't you just add a first page footer, with the same contents as your existing footer?

Re: Issuee with updating header for multipage.docx with a fo

PostPosted: Mon May 30, 2016 6:31 pm
by nishant.singh
Tried re-adding first page footer but i still get the default footer, this time copied twice.

output xml before i copy first page footer:

<w:sectPr w:rsidSect="00F75D23" w:rsidR="00963632">
<w:footerReference w:type="default" r:id="rId7"/>
<w:footerReference w:type="first" r:id="rId9"/>
<w:headerReference w:type="first" r:id="rId13"/>
<w:pgSz w:code="1" w:h="15840" w:w="12240"/>
<w:pgMar w:gutter="0" w:footer="432" w:header="720" w:left="1440" w:bottom="1152" w:right="1440" w:top="1440"/>
<w:pgNumType w:start="1"/>
<w:cols w:space="720"/>
<w:titlePg/>
</w:sectPr>

output xml after i copy first page footer at end:

<w:sectPr w:rsidSect="00F75D23" w:rsidR="00963632">
<w:footerReference w:type="default" r:id="rId7"/>
<w:footerReference w:type="first" r:id="rId9"/>
<w:headerReference w:type="first" r:id="rId13"/>
<w:footerReference w:type="first" r:id="rId9"/>
<w:pgSz w:code="1" w:h="15840" w:w="12240"/>
<w:pgMar w:gutter="0" w:footer="432" w:header="720" w:left="1440" w:bottom="1152" w:right="1440" w:top="1440"/>
<w:pgNumType w:start="1"/>
<w:cols w:space="720"/>
<w:titlePg/>
</w:sectPr>

Please help.