Search in sources :

Example 1 with WordprocessingMLPackageRender

use of org.docx4j.template.io.WordprocessingMLPackageRender in project docx4j-template by vindell.

the class AddingAFooter method main.

/**
 *  First we create the package and the factory. Then we create the footer part,
 *  which returns a relationship. This relationship is then used to create
 *  a reference. Finally we add some text to the document and save it.
 */
public static void main(String[] args) throws Docx4JException {
    WordprocessingMLPackageRender render = new WordprocessingMLPackageRender(wordMLPackage);
    wordMLPackage = WordprocessingMLPackage.createPackage();
    factory = Context.getWmlObjectFactory();
    Relationship relationship = createFooterPart();
    createFooterReference(relationship);
    wordMLPackage.getMainDocumentPart().addParagraphOfText("Hello Word!");
    wordMLPackage.save(new File("d://HelloWord14.docx"));
}
Also used : WordprocessingMLPackageRender(org.docx4j.template.io.WordprocessingMLPackageRender) Relationship(org.docx4j.relationships.Relationship) File(java.io.File)

Example 2 with WordprocessingMLPackageRender

use of org.docx4j.template.io.WordprocessingMLPackageRender in project docx4j-template by vindell.

the class AddingAnInlineImageTest method main.

/**
 *  像往常一样, 我们创建了一个包(package)来容纳文档.
 *  然后我们创建了一个指向将要添加到文档的图片的文件对象.为了能够对图片做一些操作, 我们将它转换
 *  为字节数组. 最后我们将图片添加到包中并保存这个包(package).
 */
public static void main(String[] args) throws Exception {
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    File file = new File("src/main/resources/iProfsLogo.png");
    byte[] bytes = WMLPackageUtils.imageToByteArray(file);
    WordprocessingMLPackageRender render = new WordprocessingMLPackageRender(wordMLPackage);
    render.addImageToPackage(bytes);
    wordMLPackage.save(new java.io.File("src/main/files/HelloWord7.docx"));
}
Also used : WordprocessingMLPackageRender(org.docx4j.template.io.WordprocessingMLPackageRender) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File) File(java.io.File)

Aggregations

File (java.io.File)2 WordprocessingMLPackageRender (org.docx4j.template.io.WordprocessingMLPackageRender)2 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)1 Relationship (org.docx4j.relationships.Relationship)1