Search in sources :

Example 21 with Relationship

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

Example 22 with Relationship

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

Example 23 with Relationship

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

Example 24 with Relationship

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

Example 25 with Relationship

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();
    }
}
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) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException)

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