Search in sources :

Example 6 with Ftr

use of org.docx4j.wml.Ftr in project docx4j-template by vindell.

the class Docx4J_简单例子2 method createFooterWithPageNr.

public Ftr createFooterWithPageNr(ObjectFactory factory) {
    Ftr ftr = factory.createFtr();
    P paragraph = factory.createP();
    RPr fontRPr = getRPr(factory, "宋体", "000000", "20", STHint.EAST_ASIA, false, false, false, false);
    R run = factory.createR();
    run.setRPr(fontRPr);
    paragraph.getContent().add(run);
    addPageTextField(factory, paragraph, "第");
    addFieldBegin(factory, paragraph);
    addPageNumberField(factory, paragraph);
    addFieldEnd(factory, paragraph);
    addPageTextField(factory, paragraph, "页");
    addPageTextField(factory, paragraph, " 总共");
    addFieldBegin(factory, paragraph);
    addTotalPageNumberField(factory, paragraph);
    addFieldEnd(factory, paragraph);
    addPageTextField(factory, paragraph, "页");
    setParagraphAlign(factory, paragraph, JcEnumeration.CENTER);
    ftr.getContent().add(paragraph);
    return ftr;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) Ftr(org.docx4j.wml.Ftr) RPr(org.docx4j.wml.RPr)

Example 7 with Ftr

use of org.docx4j.wml.Ftr in project docx4j-template by vindell.

the class AddingPageNrToFooter method createFooterWithPageNr.

/**
 *  As in the previous example, we create a footer and a paragraph object. But
 *  this time, instead of adding text to a run, we add a field. And just as with
 *  the table of content, we have to add a begin and end character around the
 *  actual field with the page number. Finally we add the paragraph to the
 *  content of the footer and then return it.
 *
 * @return
 */
public static Ftr createFooterWithPageNr() {
    Ftr ftr = factory.createFtr();
    P paragraph = factory.createP();
    addFieldBegin(paragraph);
    addPageNumberField(paragraph);
    addFieldEnd(paragraph);
    ftr.getContent().add(paragraph);
    return ftr;
}
Also used : P(org.docx4j.wml.P) Ftr(org.docx4j.wml.Ftr)

Example 8 with Ftr

use of org.docx4j.wml.Ftr in project docx4j-template by vindell.

the class WmlElementUtils method createFooter.

/**
 *  First we create a footer, a paragraph, a run and a text. We add the given
 *  given content to the text and add that to the run. The run is then added to
 *  the paragraph, which is in turn added to the footer. Finally we return the
 *  footer.
 *  @param content
 *  @return
 */
public static Ftr createFooter(String content) {
    Ftr footer = factory.createFtr();
    P paragraph = factory.createP();
    R run = factory.createR();
    Text text = new Text();
    text.setValue(content);
    run.getContent().add(text);
    paragraph.getContent().add(run);
    footer.getContent().add(paragraph);
    return footer;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) Ftr(org.docx4j.wml.Ftr) Text(org.docx4j.wml.Text)

Example 9 with Ftr

use of org.docx4j.wml.Ftr in project docx4j-template by vindell.

the class Docx4J_简单例子 method getTextFtr.

public Ftr getTextFtr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, JcEnumeration jcEnumeration) throws Exception {
    Ftr ftr = factory.createFtr();
    P footerP = factory.createP();
    Text text = factory.createText();
    text.setValue(content);
    R run = factory.createR();
    run.getContent().add(text);
    footerP.getContent().add(run);
    PPr pPr = footerP.getPPr();
    if (pPr == null) {
        pPr = factory.createPPr();
    }
    Jc jc = pPr.getJc();
    if (jc == null) {
        jc = new Jc();
    }
    jc.setVal(jcEnumeration);
    pPr.setJc(jc);
    footerP.setPPr(pPr);
    ftr.getContent().add(footerP);
    return ftr;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) Ftr(org.docx4j.wml.Ftr) Jc(org.docx4j.wml.Jc) Text(org.docx4j.wml.Text)

Example 10 with Ftr

use of org.docx4j.wml.Ftr in project docx4j-template by vindell.

the class Docx4J_简单例子2 method getFtr.

public Ftr getFtr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart) throws Exception {
    Ftr ftr = factory.createFtr();
    File file = new File("f:/saveFile/tmp/xxt.jpg");
    java.io.InputStream is = new java.io.FileInputStream(file);
    ftr.getContent().add(newImage(wordprocessingMLPackage, factory, sourcePart, BufferUtil.getBytesFromInputStream(is), "filename", "这是页脚", 1, 2, JcEnumeration.CENTER));
    return ftr;
}
Also used : Ftr(org.docx4j.wml.Ftr) File(java.io.File)

Aggregations

Ftr (org.docx4j.wml.Ftr)11 P (org.docx4j.wml.P)8 R (org.docx4j.wml.R)7 Jc (org.docx4j.wml.Jc)4 PPr (org.docx4j.wml.PPr)4 Text (org.docx4j.wml.Text)4 File (java.io.File)3 CTVerticalJc (org.docx4j.wml.CTVerticalJc)3 RPr (org.docx4j.wml.RPr)3 STVerticalJc (org.docx4j.wml.STVerticalJc)3 BigInteger (java.math.BigInteger)2 CTBorder (org.docx4j.wml.CTBorder)2 PBdr (org.docx4j.wml.PPrBase.PBdr)2 ParaRPr (org.docx4j.wml.ParaRPr)1