- Timestamp:
- 10/27/09 14:11:28 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/samples/CreateWordprocessingMLDocument.java
r943 r955 32 32 import org.docx4j.model.table.TblFactory; 33 33 import org.docx4j.openpackaging.packages.WordprocessingMLPackage; 34 import org.docx4j.openpackaging.parts.PartName; 35 import org.docx4j.openpackaging.parts.WordprocessingML.AlternativeFormatInputPart; 36 import org.docx4j.openpackaging.contenttype.ContentType; 34 37 import org.docx4j.openpackaging.exceptions.InvalidFormatException; 35 38 import org.docx4j.openpackaging.io.SaveToZipFile; 39 import org.docx4j.relationships.Relationship; 40 import org.docx4j.wml.CTAltChunk; 36 41 import org.docx4j.wml.Tbl; 37 42 … … 46 51 public static void main(String[] args) throws Exception { 47 52 48 boolean save = false;53 boolean save = true; 49 54 50 55 System.out.println( "Creating package.."); … … 108 113 109 114 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 110 129 //injectDocPropsCustomPart(wordMLPackage); 111 130 … … 113 132 if (save) { 114 133 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") ); 116 135 } else { 117 136 // Create a org.docx4j.wml.Package object
Note: See TracChangeset
for help on using the changeset viewer.
