コード例 #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
ファイル: DOCXWriter.java プロジェクト: haxdai/SWBPDocumenter
  /**
   * Fija la alineación de un párrafo
   *
   * @param paragraph Párrafo a alinear
   * @param alignment Valor de alineamiento
   */
  private void alignParagraph(P paragraph, JcEnumeration alignment) {
    PPr parProps = paragraph.getPPr();
    if (null == parProps) parProps = objectFactory.createPPr();
    Jc al = objectFactory.createJc();
    al.setVal(alignment);
    parProps.setJc(al);

    paragraph.setPPr(parProps);
  }
コード例 #3
0
 private void setHorizontalAlignment(P paragraph, JcEnumeration hAlign) {
   if (hAlign != null) {
     PPr pprop = paragraph.getPPr();
     if (pprop == null) {
       pprop = new PPr();
       paragraph.setPPr(pprop);
     }
     Jc align = new Jc();
     align.setVal(hAlign);
     pprop.setJc(align);
     paragraph.setPPr(pprop);
   }
 }
コード例 #4
0
  private Lvl createLevel(int level, Map<String, CSSValue> cssMap) {

    if (level > 8) level = 8; // Word can't open a document with Ilvl>8

    // Create object for lvl
    Lvl lvl = wmlObjectFactory.createLvl();
    lvl.setIlvl(BigInteger.valueOf(level));

    //            // Create object for pStyle
    //            Lvl.PStyle lvlpstyle = wmlObjectFactory.createLvlPStyle();
    //            lvl.setPStyle(lvlpstyle);
    //                lvlpstyle.setVal( "Heading1");

    // Create object for pPr
    PPr ppr = wmlObjectFactory.createPPr();
    lvl.setPPr(ppr);

    ppr.setInd(getInd(getAncestorIndentation()));

    // Create object for numFmt
    NumFmt numfmt = wmlObjectFactory.createNumFmt();
    lvl.setNumFmt(numfmt);
    numfmt.setVal(getNumberFormatFromCSSListStyleType(cssMap.get("list-style-type").getCssText()));

    // Create object for lvlText
    Lvl.LvlText lvllvltext = wmlObjectFactory.createLvlLvlText();
    lvl.setLvlText(lvllvltext);
    lvllvltext.setVal(
        getLvlTextFromCSSListStyleType(cssMap.get("list-style-type").getCssText(), level + 1));

    // Bullets have an associated font
    RFonts rfonts = geRFontsForCSSListStyleType(cssMap.get("list-style-type").getCssText());
    if (rfonts != null) {
      RPr rpr = wmlObjectFactory.createRPr();
      rpr.setRFonts(rfonts);
      lvl.setRPr(rpr);
    }

    // Create object for lvlJc
    Jc jc = wmlObjectFactory.createJc();
    lvl.setLvlJc(jc);
    jc.setVal(org.docx4j.wml.JcEnumeration.LEFT);

    // Create object for start
    Lvl.Start lvlstart = wmlObjectFactory.createLvlStart();
    lvl.setStart(lvlstart);
    lvlstart.setVal(BigInteger.valueOf(1));

    return lvl;
  }
コード例 #5
0
  private P createPageNumParagraph() {
    CTSimpleField pgnum = factory.createCTSimpleField();
    pgnum.setInstr(" PAGE \\* MERGEFORMAT ");
    RPr RPr = factory.createRPr();
    RPr.setNoProof(new BooleanDefaultTrue());
    PPr ppr = factory.createPPr();
    Jc jc = factory.createJc();
    jc.setVal(JcEnumeration.CENTER);
    ppr.setJc(jc);
    PPrBase.Spacing pprbase = factory.createPPrBaseSpacing();
    pprbase.setBefore(BigInteger.valueOf(240));
    pprbase.setAfter(BigInteger.valueOf(0));
    ppr.setSpacing(pprbase);

    R run = factory.createR();
    run.getContent().add(RPr);
    pgnum.getContent().add(run);

    JAXBElement<CTSimpleField> fldSimple = factory.createPFldSimple(pgnum);
    P para = createParagraph();
    para.getContent().add(fldSimple);
    para.setPPr(ppr);
    return para;
  }