Search in sources :

Example 6 with Relationship

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

Example 7 with Relationship

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"));
}
Also used : ObjectFactory(org.docx4j.wml.ObjectFactory) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) Relationship(org.docx4j.relationships.Relationship) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File)

Example 8 with Relationship

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

Example 9 with Relationship

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();
    }
}
Also used : PartName(org.docx4j.openpackaging.parts.PartName) ContentType(org.docx4j.openpackaging.contenttype.ContentType) Relationship(org.docx4j.relationships.Relationship) CTAltChunk(org.docx4j.wml.CTAltChunk) AlternativeFormatInputPart(org.docx4j.openpackaging.parts.WordprocessingML.AlternativeFormatInputPart) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException)

Example 10 with Relationship

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"));
}
Also used : WordprocessingMLPackageRender(org.docx4j.template.io.WordprocessingMLPackageRender) Relationship(org.docx4j.relationships.Relationship) File(java.io.File)

Aggregations

Relationship (org.docx4j.relationships.Relationship)27 FooterPart (org.docx4j.openpackaging.parts.WordprocessingML.FooterPart)7 HeaderPart (org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart)7 File (java.io.File)6 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)4 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)3 PartName (org.docx4j.openpackaging.parts.PartName)3 ObjectFactory (org.docx4j.wml.ObjectFactory)3 IOException (java.io.IOException)2 BigInteger (java.math.BigInteger)2 ContentType (org.docx4j.openpackaging.contenttype.ContentType)2 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)2 AlternativeFormatInputPart (org.docx4j.openpackaging.parts.WordprocessingML.AlternativeFormatInputPart)2 CTAltChunk (org.docx4j.wml.CTAltChunk)2 Text (com.vladsch.flexmark.ast.Text)1 AttributesNode (com.vladsch.flexmark.ext.attributes.AttributesNode)1 EnumeratedReferenceText (com.vladsch.flexmark.ext.enumerated.reference.EnumeratedReferenceText)1 FileNotFoundException (java.io.FileNotFoundException)1 JAXBException (javax.xml.bind.JAXBException)1 CTChartSpace (org.docx4j.dml.chart.CTChartSpace)1