use of org.docx4j.relationships.Relationship in project docx4j-template by vindell.
the class Docx4J_简单例子2 method createHeaderPart.
// 图片页眉
public Relationship createHeaderPart(WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory) 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));
return rel;
}
use of org.docx4j.relationships.Relationship in project docx4j-template by vindell.
the class Docx4J_简单例子2 method main.
public static void main(String[] args) throws Exception {
Docx4J_简单例子 t = new Docx4J_简单例子();
WordprocessingMLPackage wordMLPackage = t.createWordprocessingMLPackage();
MainDocumentPart mp = wordMLPackage.getMainDocumentPart();
ObjectFactory factory = Context.getWmlObjectFactory();
// 图片页眉
// Relationship relationship =t.createHeaderPart(wordMLPackage, mp, factory);
// 文字页眉
Relationship relationship = t.createTextHeaderPart(wordMLPackage, mp, factory, "我是页眉,多创造,少抄袭", JcEnumeration.CENTER);
t.createHeaderReference(wordMLPackage, mp, factory, relationship);
t.addParagraphTest(wordMLPackage, mp, factory);
t.addPageBreak(wordMLPackage, factory);
t.createNormalTableTest(wordMLPackage, mp, factory);
// 页脚
relationship = t.createFooterPageNumPart(wordMLPackage, mp, factory);
t.createFooterReference(wordMLPackage, mp, factory, relationship);
t.saveWordPackage(wordMLPackage, new File("f:/saveFile/temp/s5_simple.docx"));
}
use of org.docx4j.relationships.Relationship in project docx4j-template by vindell.
the class Docx4J_简单例子2 method createTextHeaderPart.
// 文字页面
public Relationship createTextHeaderPart(WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, String content, JcEnumeration jcEnumeration) throws Exception {
HeaderPart headerPart = new HeaderPart();
Relationship rel = t.addTargetPart(headerPart);
headerPart.setJaxbElement(getTextHdr(wordprocessingMLPackage, factory, headerPart, content, jcEnumeration));
return rel;
}
use of org.docx4j.relationships.Relationship in project docx4j-template by vindell.
the class WMLPackageUtils method insertDocx.
// 插入文档
private static void insertDocx(MainDocumentPart main, byte[] bytes, int chunkId) {
try {
AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(new PartName("/part" + chunkId + ".docx"));
afiPart.setContentType(new ContentType(CONTENT_TYPE));
afiPart.setBinaryData(bytes);
Relationship altChunkRel = main.addTargetPart(afiPart);
CTAltChunk chunk = Context.getWmlObjectFactory().createCTAltChunk();
chunk.setId(altChunkRel.getId());
main.addObject(chunk);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.docx4j.relationships.Relationship 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"));
}
Aggregations