use of org.docx4j.relationships.Relationship in project docx4j-template by vindell.
the class Docx4J_简单例子2 method createFooterPart.
// 图片页脚
public Relationship createFooterPart(WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception {
FooterPart footerPart = new FooterPart();
Relationship rel = t.addTargetPart(footerPart);
footerPart.setJaxbElement(getFtr(wordprocessingMLPackage, factory, footerPart));
return rel;
}
use of org.docx4j.relationships.Relationship 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.relationships.Relationship 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.relationships.Relationship in project docx4j-template by vindell.
the class AddingPageNrToFooter method main.
/**
* First we create the package and the factory. Then we create the footer.
* Finally we add two pages with text to the document and save it.
*/
public static void main(String[] args) throws Exception {
wordMLPackage = WordprocessingMLPackage.createPackage();
factory = Context.getWmlObjectFactory();
Relationship relationship = createFooterPart();
createFooterReference(relationship);
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
documentPart.addParagraphOfText("Hello World!");
addPageBreak(documentPart);
documentPart.addParagraphOfText("This is page 2!");
wordMLPackage.save(new File("src/main/files/HelloWord15.docx"));
}
use of org.docx4j.relationships.Relationship in project docx4j-template by vindell.
the class Docx4jUtils method insertDocx.
// 插入文档
private 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.setContentType(new ContentType(ContentTypes.APPLICATION_XML));
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();
}
}
Aggregations