Ignore:
Timestamp:
10/27/09 14:11:28 (3 years ago)
Author:
jharrop
Message:

Make altChunk work; add sample code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/samples/CreateWordprocessingMLDocument.java

    r943 r955  
    3232import org.docx4j.model.table.TblFactory; 
    3333import org.docx4j.openpackaging.packages.WordprocessingMLPackage; 
     34import org.docx4j.openpackaging.parts.PartName; 
     35import org.docx4j.openpackaging.parts.WordprocessingML.AlternativeFormatInputPart; 
     36import org.docx4j.openpackaging.contenttype.ContentType; 
    3437import org.docx4j.openpackaging.exceptions.InvalidFormatException; 
    3538import org.docx4j.openpackaging.io.SaveToZipFile; 
     39import org.docx4j.relationships.Relationship; 
     40import org.docx4j.wml.CTAltChunk; 
    3641import org.docx4j.wml.Tbl; 
    3742 
     
    4651        public static void main(String[] args) throws Exception { 
    4752                 
    48                 boolean save = false; 
     53                boolean save = true; 
    4954                 
    5055                System.out.println( "Creating package.."); 
     
    108113             
    109114                 
     115            // Add an altChunk 
     116            // .. the part 
     117            String html = "<html><head><title>Import me</title></head><body><p>Hello World!</p></body></html>"; 
     118            AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(new PartName("/hw.html") );  
     119            afiPart.setBinaryData(html.getBytes()); 
     120            afiPart.setContentType(new ContentType("text/html")); 
     121            Relationship altChunkRel = wordMLPackage.getMainDocumentPart().addTargetPart(afiPart); 
     122            // .. the bit in document body 
     123            CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk(); 
     124            ac.setId(altChunkRel.getId() ); 
     125            wordMLPackage.getMainDocumentPart().addObject(ac); 
     126            // .. content type 
     127            wordMLPackage.getContentTypeManager().addDefaultContentType("html", "text/html"); 
     128             
    110129                //injectDocPropsCustomPart(wordMLPackage); 
    111130                 
     
    113132                if (save) { 
    114133                        System.out.println("Saved."); 
    115                         wordMLPackage.save(new java.io.File(System.getProperty("user.dir") + "/bolds.docx") ); 
     134                        wordMLPackage.save(new java.io.File(System.getProperty("user.dir") + "/ac.docx") ); 
    116135                } else { 
    117136                        // Create a org.docx4j.wml.Package object 
Note: See TracChangeset for help on using the changeset viewer.