コード例 #1
0
ファイル: DOCXWriter.java プロジェクト: haxdai/SWBPDocumenter
  /**
   * Creates document footer including page number
   *
   * @param doc WordprocessingMLPackage for the document.
   * @throws InvalidFormatException
   */
  private void createFooter(WordprocessingMLPackage doc) throws InvalidFormatException {
    MainDocumentPart content = doc.getMainDocumentPart();

    // Create footer
    FooterPart footer = new FooterPart();

    Ftr ftr = objectFactory.createFtr();
    P footerParagraph = objectFactory.createP();

    setStyle(footerParagraph, "footer");

    PPr parProps = objectFactory.createPPr();
    Jc al = objectFactory.createJc();
    al.setVal(JcEnumeration.RIGHT);
    parProps.setJc(al);
    footerParagraph.setPPr(parProps);

    // Add field start
    R run = objectFactory.createR();
    FldChar fldChar = objectFactory.createFldChar();
    fldChar.setFldCharType(STFldCharType.BEGIN);
    run.getContent().add(fldChar);
    footerParagraph.getContent().add(run);

    // Add pageNumber field
    run = objectFactory.createR();
    Text txt = objectFactory.createText();
    txt.setSpace("preserve");
    txt.setValue(" PAGE   \\* MERGEFORMAT ");
    run.getContent().add(objectFactory.createRInstrText(txt));
    footerParagraph.getContent().add(run);

    // Add field end
    run = objectFactory.createR();
    fldChar = objectFactory.createFldChar();
    fldChar.setFldCharType(STFldCharType.END);
    run.getContent().add(fldChar);
    footerParagraph.getContent().add(run);

    ftr.getContent().add(footerParagraph);
    footer.setJaxbElement(ftr);

    Relationship rel = content.addTargetPart(footer);

    // Relate footer 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);
    }

    FooterReference footerReference = objectFactory.createFooterReference();
    footerReference.setId(rel.getId());
    footerReference.setType(HdrFtrRef.DEFAULT);
    sectPr.getEGHdrFtrReferences().add(footerReference);
  }
コード例 #2
0
ファイル: WordOutputFactory.java プロジェクト: fritsric/EPIM
  /**
   * Nastaví záhlaví dokumentu. Úprava předchozí funkce.
   *
   * @param irPackage
   * @throws InvalidFormatException
   */
  private Ftr SetupFooter(WordprocessingMLPackage irPackage) throws InvalidFormatException {
    ObjectFactory lrFactory = Context.getWmlObjectFactory();

    /* create header part */
    FooterPart lrFooterPart = new FooterPart();
    lrFooterPart.setPackage(irPackage);

    Ftr lrFooter = lrFactory.createFtr();

    lrFooterPart.setJaxbElement(lrFooter);
    Relationship lrRelationship = irPackage.getMainDocumentPart().addTargetPart(lrFooterPart);
    /* end create header part */

    /* create header reference */
    List<SectionWrapper> lrSections = irPackage.getDocumentModel().getSections();
    SectPr lrSectionPr = lrSections.get(lrSections.size() - 1).getSectPr();
    // There is always a section wrapper, but it might not contain a sectPr
    if (lrSectionPr == null) {
      lrSectionPr = lrFactory.createSectPr();
      irPackage.getMainDocumentPart().addObject(lrSectionPr);
      lrSections.get(lrSections.size() - 1).setSectPr(lrSectionPr);
    }

    FooterReference lrFooterReference = lrFactory.createFooterReference();
    lrFooterReference.setId(lrRelationship.getId());
    lrFooterReference.setType(HdrFtrRef.DEFAULT);
    lrSectionPr.getEGHdrFtrReferences().add(lrFooterReference); // add header or footer references
    /* end create header reference */

    return lrFooter;
  }
コード例 #3
0
 private Relationship createFooterPart(WordprocessingMLPackage wordprocessingMLPackage, Tbl table)
     throws Exception {
   FooterPart footerPart = new FooterPart();
   Relationship rel = wordprocessingMLPackage.getMainDocumentPart().addTargetPart(footerPart);
   // After addTargetPart, so image can be added properly
   footerPart.setJaxbElement(getFtr(wordprocessingMLPackage, footerPart, table));
   return rel;
 }