Ignore:
Timestamp:
10/25/09 01:08:24 (3 years ago)
Author:
jharrop
Message:

Added DocumentModel?. DocumentModel? is a list of SectionWrappers?; a SectionWrapper? has a HeaderFooterPolicy?, PageDimensions? and sectPr.
HeaderFooterPolicy? moved to new package, as there will be 1 per SectionWrapper?.

TblFactory? is a way to create simple tables; now used in the Create..Document sample.

Debug of JAXBElement.
NamespacePrefixMapper?: convenient static method.

WordXmlPicture?: add @id,containing relId.

MDP styles in use:recurse into tables

File:
1 edited

Legend:

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

    r565 r943  
    2424import java.io.File; 
    2525 
     26import javax.xml.bind.JAXBContext; 
     27import javax.xml.bind.Marshaller; 
     28 
     29import org.docx4j.convert.out.flatOpcXml.FlatOpcXmlCreator; 
     30import org.docx4j.jaxb.Context; 
     31import org.docx4j.jaxb.NamespacePrefixMapperUtils; 
     32import org.docx4j.model.table.TblFactory; 
    2633import org.docx4j.openpackaging.packages.WordprocessingMLPackage; 
    2734import org.docx4j.openpackaging.exceptions.InvalidFormatException; 
    2835import org.docx4j.openpackaging.io.SaveToZipFile; 
     36import org.docx4j.wml.Tbl; 
    2937 
    3038/** 
     
    3745 
    3846        public static void main(String[] args) throws Exception { 
     47                 
     48                boolean save = false; 
    3949                 
    4050                System.out.println( "Creating package.."); 
     
    8797                                org.docx4j.XmlUtils.unmarshalString(str) ); 
    8898             
    89                  
    90                 System.out.println( ".. done!"); 
     99            // Let's add a table 
     100            int writableWidthTwips = wordMLPackage.getDocumentModel().getSections().get(0).getPageDimensions().getWritableWidthTwips(); 
     101            int cols = 3; 
     102            int cellWidthTwips = new Double(  
     103                                                                Math.floor( (writableWidthTwips/cols )) 
     104                                                                        ).intValue(); 
     105             
     106            Tbl tbl = TblFactory.createTable(3, 3, cellWidthTwips); 
     107            wordMLPackage.getMainDocumentPart().addObject(tbl); 
     108             
    91109                 
    92110                //injectDocPropsCustomPart(wordMLPackage); 
    93111                 
    94                 // Now save it  
    95                 wordMLPackage.save(new java.io.File(System.getProperty("user.dir") + "/bolds.docx") ); 
     112                // Now save it 
     113                if (save) { 
     114                        System.out.println("Saved."); 
     115                        wordMLPackage.save(new java.io.File(System.getProperty("user.dir") + "/bolds.docx") ); 
     116                } else { 
     117                        // Create a org.docx4j.wml.Package object 
     118                        FlatOpcXmlCreator worker = new FlatOpcXmlCreator(wordMLPackage); 
     119                        org.docx4j.xmlPackage.Package pkg = worker.get(); 
     120                 
     121                // Now marshall it 
     122                        JAXBContext jc = Context.jcXmlPackage; 
     123                        Marshaller marshaller=jc.createMarshaller(); 
     124                         
     125                        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); 
     126                        NamespacePrefixMapperUtils.setProperty(marshaller,  
     127                                        NamespacePrefixMapperUtils.getPrefixMapper());                   
     128                        System.out.println( "\n\n OUTPUT " ); 
     129                        System.out.println( "====== \n\n " );    
     130                        marshaller.marshal(pkg, System.out);                             
     131                         
     132                } 
    96133                 
    97134                System.out.println("Done."); 
Note: See TracChangeset for help on using the changeset viewer.