Search in sources :

Example 1 with ContentType

use of org.docx4j.openpackaging.contenttype.ContentType 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 2 with ContentType

use of org.docx4j.openpackaging.contenttype.ContentType 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

IOException (java.io.IOException)2 ContentType (org.docx4j.openpackaging.contenttype.ContentType)2 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)2 PartName (org.docx4j.openpackaging.parts.PartName)2 AlternativeFormatInputPart (org.docx4j.openpackaging.parts.WordprocessingML.AlternativeFormatInputPart)2 Relationship (org.docx4j.relationships.Relationship)2 CTAltChunk (org.docx4j.wml.CTAltChunk)2 FileNotFoundException (java.io.FileNotFoundException)1 JAXBException (javax.xml.bind.JAXBException)1