Ignore:
Timestamp:
07/09/11 06:42:23 (11 months ago)
Author:
jharrop
Message:

docx4j.properties, supports configuration of default page size, margins, orientation; also ability to set some of the doc props metadata (Application & AppVersion?; dc.creator & dc.lastModifiedBy).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages/WordprocessingMLPackage.java

    r1567 r1604  
    3939 
    4040import org.apache.log4j.Logger; 
     41import org.docx4j.Docx4jProperties; 
    4142import org.docx4j.XmlUtils; 
    4243import org.docx4j.convert.out.flatOpcXml.FlatOpcXmlCreator; 
     
    385386         
    386387 
     388        /** 
     389         * Creates a WordprocessingMLPackage, using default page size and orientation. 
     390         * From 2.7.1, these are read from docx4j.properties, or if not found, default 
     391         * to A4 portrait. 
     392         */ 
    387393        public static WordprocessingMLPackage createPackage() throws InvalidFormatException { 
    388  
    389                 return createPackage(PageSizePaper.A4, false);  
     394                 
     395                String papersize= Docx4jProperties.getProperties().getProperty("docx4j.PageSize", "A4"); 
     396                log.info("Using paper size: " + papersize); 
     397                 
     398                String landscapeString = Docx4jProperties.getProperties().getProperty("docx4j.PageOrientationLandscape", "false"); 
     399                boolean landscape= Boolean.parseBoolean(landscapeString); 
     400                log.info("Landscape orientation: " + landscape); 
     401                 
     402                return createPackage( 
     403                                PageSizePaper.valueOf(papersize), landscape);  
    390404        } 
    391405         
     
    437451                        log.error(e); 
    438452                } 
     453                 
     454                // Metadata: docx4j 2.7.1 can populate some of this from docx4j.properties 
     455                DocPropsCorePart core = new DocPropsCorePart(); 
     456                org.docx4j.docProps.core.ObjectFactory coreFactory = new org.docx4j.docProps.core.ObjectFactory(); 
     457                core.setJaxbElement(coreFactory.createCoreProperties() ); 
     458                wmlPack.addTargetPart(core); 
     459                 
     460                DocPropsExtendedPart app = new DocPropsExtendedPart(); 
     461                org.docx4j.docProps.extended.ObjectFactory extFactory = new org.docx4j.docProps.extended.ObjectFactory(); 
     462                app.setJaxbElement(extFactory.createProperties() ); 
     463                wmlPack.addTargetPart(app);              
     464                 
    439465                // Return the new package 
    440466                return wmlPack; 
Note: See TracChangeset for help on using the changeset viewer.