/** * Creates document header including process name * * @param doc WordprocessingMLPackage for the document. * @throws InvalidFormatException */ private void createHeader(WordprocessingMLPackage doc) throws InvalidFormatException { MainDocumentPart content = doc.getMainDocumentPart(); // Create header HeaderPart header = new HeaderPart(); Relationship rel = content.addTargetPart(header); Hdr hdr = objectFactory.createHdr(); P headerParagraph = content.createParagraphOfText(p.getTitle()); hdr.getContent().add(headerParagraph); header.setJaxbElement(hdr); setStyle(headerParagraph, "Header"); alignParagraph(headerParagraph, JcEnumeration.CENTER); // Relate to document List<SectionWrapper> sections = doc.getDocumentModel().getSections(); SectPr sectPr = sections.get(sections.size() - 1).getSectPr(); if (null == sectPr) { sectPr = objectFactory.createSectPr(); content.addObject(sectPr); sections.get(sections.size() - 1).setSectPr(sectPr); } HeaderReference headerReference = objectFactory.createHeaderReference(); headerReference.setId(rel.getId()); headerReference.setType(HdrFtrRef.DEFAULT); sectPr.getEGHdrFtrReferences().add(headerReference); }
private Hdr getHdr(WordprocessingMLPackage wordprocessingMLPackage, Part sourcePart, Tbl table) throws Exception { Hdr hdr = factory.createHdr(); if (hasPageNoHeader) { hdr.getContent().add(createPageNumParagraph()); } else { hdr.getContent().add(table); } return hdr; }