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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations