use of org.docx4j.openpackaging.parts.WordprocessingML.FooterPart in project docx4j-template by vindell.
the class Docx4jTest method main.
public static void main(String[] args) throws Exception {
// 创建一个word
// 读取可以使用WordprocessingMLPackage.load方法
WordprocessingMLPackage word = WordprocessingMLPackage.createPackage();
String imageFilePath = Docx4jTest.class.getResource("/lw.jpg").getPath();
// 创建页眉
HeaderPart headerPart = createHeader(word);
// 页眉添加图片
headerPart.getContent().add(newImage(word, headerPart, imageFilePath));
// 创建页脚
FooterPart footerPart = createFooter(word);
// 添加图片
footerPart.getContent().add(newImage(word, footerPart, imageFilePath));
// 主内容添加文本和图片
word.getMainDocumentPart().getContent().add(newText("http://www.mybatis.tk"));
word.getMainDocumentPart().getContent().add(newText("http://blog.csdn.net/isea533"));
word.getMainDocumentPart().getContent().add(newImage(word, word.getMainDocumentPart(), imageFilePath));
// 保存
word.save(new File("d:/1.docx"));
}
use of org.docx4j.openpackaging.parts.WordprocessingML.FooterPart in project docx4j-template by vindell.
the class Docx4jTest method createFooter.
/**
* 创建页脚
*
* @param word
* @return
* @throws Exception
*/
public static FooterPart createFooter(WordprocessingMLPackage word) throws Exception {
FooterPart footerPart = new FooterPart();
Relationship rel = word.getMainDocumentPart().addTargetPart(footerPart);
createFooterReference(word, rel);
return footerPart;
}
use of org.docx4j.openpackaging.parts.WordprocessingML.FooterPart in project docx4j-template by vindell.
the class AddingAFooter method createFooterPart.
/**
* This method creates a footer part and set the package on it. Then we add some
* text and add the footer part to the package. Finally we return the
* corresponding relationship.
*
* @return
* @throws InvalidFormatException
*/
private static Relationship createFooterPart() throws InvalidFormatException {
FooterPart footerPart = new FooterPart();
footerPart.setPackage(wordMLPackage);
footerPart.setJaxbElement(WmlElementUtils.createFooter("Text"));
return wordMLPackage.getMainDocumentPart().addTargetPart(footerPart);
}
Aggregations