use of org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart in project docx4j-template by vindell.
the class Docx4J_例子2 method createHeaderPart.
// 图片页眉
public Relationship createHeaderPart(WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, boolean isUnderLine, String underLineSize) throws Exception {
HeaderPart headerPart = new HeaderPart();
Relationship rel = t.addTargetPart(headerPart);
// After addTargetPart, so image can be added properly
headerPart.setJaxbElement(getHdr(wordprocessingMLPackage, factory, headerPart, isUnderLine, underLineSize));
return rel;
}
use of org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart in project docx4j-template by vindell.
the class Docx4jTest method createHeader.
/**
* 创建页眉
*
* @param word
* @return
* @throws Exception
*/
public static HeaderPart createHeader(WordprocessingMLPackage word) throws Exception {
HeaderPart headerPart = new HeaderPart();
Relationship rel = word.getMainDocumentPart().addTargetPart(headerPart);
createHeaderReference(word, rel);
return headerPart;
}
use of org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart 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"));
}
Aggregations