Search in sources :

Example 11 with FooterPart

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"));
}
Also used : FooterPart(org.docx4j.openpackaging.parts.WordprocessingML.FooterPart) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File) HeaderPart(org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart)

Example 12 with FooterPart

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;
}
Also used : FooterPart(org.docx4j.openpackaging.parts.WordprocessingML.FooterPart) Relationship(org.docx4j.relationships.Relationship)

Example 13 with 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);
}
Also used : FooterPart(org.docx4j.openpackaging.parts.WordprocessingML.FooterPart)

Aggregations

FooterPart (org.docx4j.openpackaging.parts.WordprocessingML.FooterPart)13 Relationship (org.docx4j.relationships.Relationship)7 File (java.io.File)1 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)1 HeaderPart (org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart)1