// doesn't seem that .docx properly supports that
// feature of the file format yet
CTSectPr sectPr = doc.getDocumentBody().getSectPr();
for(int i=0; i<sectPr.sizeOfHeaderReferenceArray(); i++) {
// Get the header
CTHdrFtrRef ref = sectPr.getHeaderReferenceArray(i);
PackagePart hdrPart = doc.getPartById(ref.getId());
XWPFHeader hdr = new XWPFHeader(
HdrDocument.Factory.parse(hdrPart.getInputStream()).getHdr()
);
// Assign it
if(ref.getType() == STHdrFtr.FIRST) {
firstPageHeader = hdr;
} else if(ref.getType() == STHdrFtr.EVEN) {
evenPageHeader = hdr;
} else {
defaultHeader = hdr;
}
}
for(int i=0; i<sectPr.sizeOfFooterReferenceArray(); i++) {
// Get the footer
CTHdrFtrRef ref = sectPr.getFooterReferenceArray(i);
PackagePart ftrPart = doc.getPartById(ref.getId());
XWPFFooter ftr = new XWPFFooter(
FtrDocument.Factory.parse(ftrPart.getInputStream()).getFtr()
);
// Assign it
if(ref.getType() == STHdrFtr.FIRST) {
firstPageFooter = ftr;
} else if(ref.getType() == STHdrFtr.EVEN) {
evenPageFooter = ftr;
} else {
defaultFooter = ftr;
}
}