Changeset 1567


Ignore:
Timestamp:
06/25/11 11:45:55 (11 months ago)
Author:
jharrop
Message:

Rework/cleanup PageDimensions?

Location:
trunk/docx4j/src/main/java/org/docx4j
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/convert/out/pdf/viaXSLFO/LayoutMasterSetBuilder.java

    r1182 r1567  
    187187        //   <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/> 
    188188 
    189                 spm.setPageHeight( UnitsOfMeasurement.twipToBest(page.getPageHeight())); 
    190                 spm.setPageWidth(  UnitsOfMeasurement.twipToBest(page.getPageWidth())); 
    191                  
    192                 spm.setMarginLeft( UnitsOfMeasurement.twipToBest(page.getMarginLeft()) ); 
    193                 spm.setMarginRight( UnitsOfMeasurement.twipToBest(page.getMarginRight()) ); 
     189                spm.setPageHeight( UnitsOfMeasurement.twipToBest(page.getPgSz().getH().intValue() )); 
     190                spm.setPageWidth(  UnitsOfMeasurement.twipToBest(page.getPgSz().getW().intValue() )); 
     191                 
     192                spm.setMarginLeft( UnitsOfMeasurement.twipToBest(page.getPgMar().getLeft().intValue() ) ); 
     193                spm.setMarginRight( UnitsOfMeasurement.twipToBest(page.getPgMar().getRight().intValue()) ); 
    194194                 
    195195                /*  
     
    227227                        // Make margin smaller, because header takes up space it would otherwise occupy   
    228228                        int marginTopTwips  
    229                                 = page.getMarginTop()  
    230                                         - (HEADER_PADDING_TWIP + page.getHeaderExtent() + page.getMarginHeader()); 
     229                                = page.getPgMar().getTop().intValue()  
     230                                        - (HEADER_PADDING_TWIP + page.getHeaderExtent() + page.getPgMar().getHeader().intValue()); 
    231231                        if (marginTopTwips<MIN_PAGE_MARGIN) marginTopTwips=MIN_PAGE_MARGIN;                              
    232232                        spm.setMarginTop( UnitsOfMeasurement.twipToBest(marginTopTwips ) ); 
     
    240240                } else { 
    241241                        // No header 
    242                         spm.setMarginTop( UnitsOfMeasurement.twipToBest(page.getMarginTop() ) ); 
     242                        spm.setMarginTop( UnitsOfMeasurement.twipToBest(page.getPgMar().getTop().intValue() ) ); 
    243243                } 
    244244 
     
    251251                        // Make margin smaller, because footer takes up space it would otherwise occupy   
    252252                        int marginBottomTwips 
    253                                         = page.getMarginBottom() 
    254                                                 - (FOOTER_PADDING_TWIP + page.getFooterExtent() + page.getMarginFooter() ); 
     253                                        = page.getPgMar().getBottom().intValue() 
     254                                                - (FOOTER_PADDING_TWIP + page.getFooterExtent() + page.getPgMar().getFooter().intValue() ); 
    255255                        if (marginBottomTwips<MIN_PAGE_MARGIN) marginBottomTwips=MIN_PAGE_MARGIN;                        
    256256                        log.debug("marginBottomTwips: " + marginBottomTwips ); 
     
    265265                } else { 
    266266                        // No footer 
    267                         spm.setMarginBottom( UnitsOfMeasurement.twipToBest(page.getMarginBottom()) ); 
     267                        spm.setMarginBottom( UnitsOfMeasurement.twipToBest(page.getPgMar().getBottom().intValue()) ); 
    268268                } 
    269269                 
  • trunk/docx4j/src/main/java/org/docx4j/model/structure/DocumentModel.java

    r1352 r1567  
    5454        protected static Logger log = Logger.getLogger(DocumentModel.class);             
    5555         
    56         private List<SectionWrapper> sections = new ArrayList<SectionWrapper>();  
    57          
    58         // Consider whether this class should store a reference to the 
    59         // org.docx4j.wml.Document?  Not until there is a demonstrable 
    60         // need. 
     56        private List<SectionWrapper> sections;   
     57        private WordprocessingMLPackage wordMLPackage; 
    6158         
    6259        // At present, objects (eg w:p, w:tbl) don't know which 
     
    6966        public DocumentModel(WordprocessingMLPackage wordMLPackage) { 
    7067                 
     68                this.wordMLPackage = wordMLPackage; 
     69                refresh(); 
     70        } 
     71         
     72        /** 
     73         * If you have added/deleted sections from your WordprocessingMLPackage, 
     74         * you'll need to call this method in order for the changes to be 
     75         * reflected in the DocumentModel. 
     76         */ 
     77        public void refresh() { 
     78                 
    7179                RelationshipsPart rels = wordMLPackage.getMainDocumentPart().getRelationshipsPart(); 
    7280                                 
     
    7583                HeaderFooterPolicy previousHF = null; 
    7684                 
    77                 for (Object o : doc.getBody().getEGBlockLevelElts() ) { 
     85                sections = new ArrayList<SectionWrapper>(); 
     86                for (Object o : doc.getBody().getContent() ) { 
    7887                        if (o instanceof org.docx4j.wml.P) { 
    7988                                if (((org.docx4j.wml.P)o).getPPr() != null ) { 
  • trunk/docx4j/src/main/java/org/docx4j/model/structure/PageDimensions.java

    r1537 r1567  
    2525import org.docx4j.jaxb.Context; 
    2626import org.docx4j.wml.STPageOrientation; 
     27import org.docx4j.wml.SectPr; 
    2728import org.docx4j.wml.SectPr.PgMar; 
    2829import org.docx4j.wml.SectPr.PgSz; 
    2930 
     31/** 
     32 * Wraps PgSz (Page size) and PgMar (margin settings). 
     33 * - gives you an easy way to set these; 
     34 * - performs a few useful calculations 
     35 *  
     36 * Used in SectionWrapper, to store the dimensions 
     37 * of a page for a section; can also be used to 
     38 * store a set of page dimensions which aren't 
     39 * associated with any section.  
     40 *  
     41 * @author jharrop 
     42 * 
     43 */ 
    3044public class PageDimensions { 
    3145         
    32         // Defaults - if values aren't defined in sectPr  
    33         // TODO - defaults page size and margins in a .properties file   
    34  
    35         public static int DEFAULT_PAGE_WIDTH_TWIPS = 12240;  // Letter; A4 would be 11907   
    36         public static int DEFAULT_LEFT_MARGIN_TWIPS = 1440;  // 1 inch 
    37         public static int DEFAULT_RIGHT_MARGIN_TWIPS = 1440; 
    38         // TODO - defaults for the other fields 
    39                  
    40         int pageWidth = DEFAULT_PAGE_WIDTH_TWIPS; 
    41         int pageHeight = 15840;  // Letter 
    42          
    43         int marginTop = 1440; 
    44         int marginBottom = 1440; 
    45         int marginLeft = DEFAULT_LEFT_MARGIN_TWIPS; 
    46         int marginRight = DEFAULT_RIGHT_MARGIN_TWIPS; 
    47  
    48         int marginHeader = 708; 
    49         int marginFooter = 708; 
    50         int marginGutter = 0;            
    51          
    52 //      @Deprecated 
    53 //      public void setA4Defaults() { 
    54 //              /* Mimic 
    55 //                      <w:pgSz w:w="12240" w:h="15840"/>^M 
    56 //            <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440"  
    57 //                       w:header="708" w:footer="708" w:gutter="0"/> 
    58 //               */ 
    59 //              pageWidth = DEFAULT_PAGE_WIDTH_TWIPS; 
    60 //              pageHeight = 15840; 
    61 //               
    62 //              marginTop = 1440; 
    63 //              marginBottom = 1440; 
    64 //              marginLeft = DEFAULT_LEFT_MARGIN_TWIPS; 
    65 //              marginRight = DEFAULT_RIGHT_MARGIN_TWIPS; 
    66 // 
    67 //              marginHeader = 708; 
    68 //              marginFooter = 708; 
    69 //              marginGutter = 0;                
    70 //      } 
    71          
     46        // TODO - defaults page size and margins in a .properties file?  
     47         
     48        public PageDimensions() { 
     49                pgSz = Context.getWmlObjectFactory().createSectPrPgSz(); 
     50                setPgSize(PageSizePaper.A4, false );             
     51                 
     52                pgMar = Context.getWmlObjectFactory().createSectPrPgMar(); 
     53                setMargins(MarginsWellKnown.NORMAL); 
     54        } 
     55 
     56        /** 
     57         * @since 2.7 
     58         */ 
     59        public PageDimensions(PgSz pgSz, PgMar pgMar) { 
     60                init(pgSz, pgMar); 
     61        } 
     62         
     63        /** 
     64         * @since 2.7 
     65         */ 
     66        public PageDimensions(SectPr sectPr) { 
     67                if (sectPr==null) { 
     68                        init(null, null); 
     69                } else { 
     70                        init(sectPr.getPgSz(), sectPr.getPgMar()); 
     71                } 
     72        } 
     73         
     74        private void init(PgSz pgSz, PgMar pgMar) { 
     75                 
     76                if (pgSz == null) { 
     77                        pgSz = Context.getWmlObjectFactory().createSectPrPgSz();                         
     78                } else { 
     79                        this.pgSz = pgSz;                        
     80                } 
     81                 
     82                if (pgMar ==null) { 
     83                        pgMar = Context.getWmlObjectFactory().createSectPrPgMar();                       
     84                } else { 
     85                        this.pgMar = pgMar;                              
     86                } 
     87        } 
     88         
     89        private PgSz pgSz; 
     90        /** 
     91         * @since 2.7 
     92         */ 
     93        public PgSz getPgSz() { 
     94                return pgSz; 
     95        } 
     96        /** 
     97         * @since 2.7 
     98         */ 
     99        public void setPgSz(PgSz pgSz) { 
     100                this.pgSz = pgSz; 
     101        } 
     102 
     103        private PgMar pgMar; 
     104        /** 
     105         * @since 2.7 
     106         */ 
     107        public PgMar getPgMar() { 
     108                return pgMar; 
     109        } 
     110        /** 
     111         * @since 2.7 
     112         */ 
     113        public void setPgMar(PgMar pgMar) { 
     114                this.pgMar = pgMar; 
     115        } 
     116 
     117                 
    72118        /** 
    73119         * @since 2.7 
     
    77123//          NORMAL("normal"),     // <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/> 
    78124                if (m.equals(MarginsWellKnown.NORMAL)) { 
    79                         marginTop = 1440; 
    80                         marginBottom = 1440; 
    81                         marginLeft = 1440; 
    82                         marginRight = 1440; 
     125                        pgMar.setTop( BigInteger.valueOf(1440)); 
     126                        pgMar.setBottom( BigInteger.valueOf(1440)); 
     127                        pgMar.setLeft( BigInteger.valueOf(1440)); 
     128                        pgMar.setRight( BigInteger.valueOf(1440)); 
    83129                        return;                  
    84130                } 
     
    86132//          NARROW("narrow"),     // <w:pgMar w:top="720"  w:right="720"  w:bottom="720"  w:left="720" w:header="708" w:footer="708" w:gutter="0"/> 
    87133                if (m.equals(MarginsWellKnown.NARROW)) { 
    88                         marginTop = 720; 
    89                         marginBottom = 720; 
    90                         marginLeft = 720; 
    91                         marginRight = 720; 
     134                        pgMar.setTop( BigInteger.valueOf(720)); 
     135                        pgMar.setBottom( BigInteger.valueOf(720)); 
     136                        pgMar.setLeft( BigInteger.valueOf(720)); 
     137                        pgMar.setRight( BigInteger.valueOf(720)); 
    92138                        return;                  
    93139                } 
     
    95141//          MODERATE("moderate"), // <w:pgMar w:top="1440" w:right="1080" w:bottom="1440" w:left="1080" w:header="708" w:footer="708" w:gutter="0"/> 
    96142                if (m.equals(MarginsWellKnown.MODERATE)) { 
    97                         marginTop = 1440; 
    98                         marginBottom = 1440; 
    99                         marginLeft = 1080; 
    100                         marginRight = 1080; 
     143                        pgMar.setTop( BigInteger.valueOf(1440)); 
     144                        pgMar.setBottom( BigInteger.valueOf(1440)); 
     145                        pgMar.setLeft( BigInteger.valueOf(1080)); 
     146                        pgMar.setRight( BigInteger.valueOf(1080)); 
    101147                        return;                  
    102148                } 
     
    104150//          WIDE("wide");         // <w:pgMar w:top="1440" w:right="2880" w:bottom="1440" w:left="2880" w:header="708" w:footer="708" w:gutter="0"/> 
    105151                if (m.equals(MarginsWellKnown.WIDE)) { 
    106                         marginTop = 1440; 
    107                         marginBottom = 1440; 
    108                         marginLeft = 2880; 
    109                         marginRight = 2880; 
    110                         return;                  
    111                 } 
    112                  
    113         } 
    114          
    115         public void setPageSize(PgSz pgSz ) { 
    116                  
    117                 if (pgSz!=null) { 
    118                         if (pgSz.getW()!=null) { 
    119                                 pageWidth = pgSz.getW().intValue(); 
    120                         } 
    121                         if (pgSz.getH()!=null) { 
    122                                 pageHeight = pgSz.getH().intValue(); 
    123                         } 
    124                 }                
    125         } 
    126          
    127         /** 
    128          * @since 2.7 
    129          */ 
    130         public static PgSz createPgSize(PageSizePaper sz, boolean landscape ) { 
    131                  
    132                 PgSz pgSz = Context.getWmlObjectFactory().createSectPrPgSz(); 
    133                  
     152                        pgMar.setTop( BigInteger.valueOf(1440)); 
     153                        pgMar.setBottom( BigInteger.valueOf(1440)); 
     154                        pgMar.setLeft( BigInteger.valueOf(2880)); 
     155                        pgMar.setRight( BigInteger.valueOf(2880)); 
     156                        return;                  
     157                } 
     158                 
     159        } 
     160         
     161        /** 
     162         * @since 2.7 
     163         */ 
     164        public void setPgSize(PageSizePaper sz, boolean landscape ) { 
     165                                 
    134166                if (sz.equals(PageSizePaper.LETTER)) { 
    135167                        pgSz.setCode(BigInteger.valueOf(1)); 
     
    196228                        } 
    197229                } 
    198                 return pgSz; 
    199230        }        
    200          
    201         public PgSz createPgSize() { 
    202                  
    203                 PgSz pgSz = Context.getWmlObjectFactory().createSectPrPgSz(); 
    204                  
    205                 pgSz.setW( BigInteger.valueOf(pageWidth) ); 
    206                 pgSz.setH( BigInteger.valueOf(pageHeight) ); 
    207                  
    208                  
    209                 return pgSz;             
    210         } 
    211          
    212         public void setMargins(PgMar pgMar) { 
    213                                  
    214                 if (pgMar!=null) { 
    215                         if (pgMar.getTop()!=null) { 
    216                                 marginTop = pgMar.getTop().intValue(); 
    217                         } 
    218                  
    219                         if (pgMar.getBottom()!=null) { 
    220                                 marginBottom = pgMar.getBottom().intValue(); 
    221                         } 
    222                         if (pgMar.getLeft()!=null) { 
    223                                 marginLeft = pgMar.getLeft().intValue(); 
    224                         } 
    225                         if (pgMar.getRight()!=null) { 
    226                                 marginRight = pgMar.getRight().intValue(); 
    227                         } 
    228                          
    229                         if (pgMar.getHeader()!=null) { 
    230                                 marginHeader = pgMar.getHeader().intValue(); 
    231                         } 
    232                         if (pgMar.getFooter()!=null) { 
    233                                 marginFooter = pgMar.getFooter().intValue(); 
    234                         } 
    235                         if (pgMar.getGutter()!=null) { 
    236                                 marginGutter = pgMar.getGutter().intValue(); 
    237                         } 
    238                 }                
    239         } 
    240  
    241         public PgMar createPgMar() { 
    242                  
    243                 PgMar pgMar = Context.getWmlObjectFactory().createSectPrPgMar(); 
    244                  
    245                 pgMar.setTop(    BigInteger.valueOf(marginTop) ); 
    246                 pgMar.setBottom( BigInteger.valueOf(marginBottom) ); 
    247                 pgMar.setLeft(   BigInteger.valueOf(marginLeft) ); 
    248                 pgMar.setRight(  BigInteger.valueOf(marginRight) ); 
    249  
    250                 pgMar.setHeader( BigInteger.valueOf(marginHeader) ); 
    251                 pgMar.setFooter( BigInteger.valueOf(marginFooter) ); 
    252                 pgMar.setGutter( BigInteger.valueOf(marginGutter) ); 
    253                  
    254                 return pgMar;            
    255         } 
    256          
    257          
    258         /** 
    259          * @return the pageWidth 
    260          */ 
    261         public int getPageWidth() { 
    262                 return pageWidth; 
    263         } 
    264  
    265         /** 
    266          * @param pageWidth the pageWidth to set 
    267          */ 
    268         public void setPageWidth(int pageWidth) { 
    269                 this.pageWidth = pageWidth; 
    270         } 
    271          
    272         public int getWritableWidthTwips() { 
    273                 return pageWidth - (marginLeft + marginRight);           
    274         } 
    275  
    276         /** 
    277          * @return the pageHeight 
    278          */ 
    279         public int getPageHeight() { 
    280                 return pageHeight; 
    281         } 
    282  
    283         /** 
    284          * @param pageHeight the pageHeight to set 
    285          */ 
    286         public void setPageHeight(int pageHeight) { 
    287                 this.pageHeight = pageHeight; 
    288         } 
    289  
    290         /** 
    291          * @return the marginTop 
    292          */ 
    293         public int getMarginTop() { 
    294                 return marginTop; 
    295         } 
    296  
    297         /** 
    298          * @param marginTop the marginTop to set 
    299          */ 
    300         public void setMarginTop(int marginTop) { 
    301                 this.marginTop = marginTop; 
    302         } 
    303  
    304         /** 
    305          * @return the marginBottom 
    306          */ 
    307         public int getMarginBottom() { 
    308                 return marginBottom; 
    309         } 
    310  
    311         /** 
    312          * @param marginBottom the marginBottom to set 
    313          */ 
    314         public void setMarginBottom(int marginBottom) { 
    315                 this.marginBottom = marginBottom; 
    316         } 
    317  
    318         /** 
    319          * @return the marginLeft 
    320          */ 
    321         public int getMarginLeft() { 
    322                 return marginLeft; 
    323         } 
    324  
    325         /** 
    326          * @param marginLeft the marginLeft to set 
    327          */ 
    328         public void setMarginLeft(int marginLeft) { 
    329                 this.marginLeft = marginLeft; 
    330         } 
    331  
    332         /** 
    333          * @return the marginRight 
    334          */ 
    335         public int getMarginRight() { 
    336                 return marginRight; 
    337         } 
    338  
    339         /** 
    340          * @param marginRight the marginRight to set 
    341          */ 
    342         public void setMarginRight(int marginRight) { 
    343                 this.marginRight = marginRight; 
    344         } 
    345  
    346         /** 
    347          * @return the marginHeader 
    348          */ 
    349         public int getMarginHeader() { 
    350                 return marginHeader; 
    351         } 
    352  
    353         /** 
    354          * @param marginHeader the marginHeader to set 
    355          */ 
    356         public void setMarginHeader(int marginHeader) { 
    357                 this.marginHeader = marginHeader; 
    358         } 
    359  
    360         /** 
    361          * @return the marginFooter 
    362          */ 
    363         public int getMarginFooter() { 
    364                 return marginFooter; 
    365         } 
    366  
    367         /** 
    368          * @param marginFooter the marginFooter to set 
    369          */ 
    370         public void setMarginFooter(int marginFooter) { 
    371                 this.marginFooter = marginFooter; 
    372         } 
    373  
    374         /** 
    375          * @return the marginGutter 
    376          */ 
    377         public int getMarginGutter() { 
    378                 return marginGutter; 
    379         } 
    380  
    381         /** 
    382          * @param marginGutter the marginGutter to set 
    383          */ 
    384         public void setMarginGutter(int marginGutter) { 
    385                 this.marginGutter = marginGutter; 
     231                 
     232        public int getWritableWidthTwips() {             
     233                return pgSz.getW().intValue() - (pgMar.getLeft().intValue() + pgMar.getRight().intValue()); 
    386234        } 
    387235 
     
    401249         *  
    402250         * Instead, this class allows headerExtent and footerExtent to be 
    403          * set as required (in TWIPS).  In due course (when we have an algorirthm for amount of  
     251         * set as required (in TWIPS).  In due course (when we have an algorithm for amount of  
    404252         * space occupied), it may be possible to do this automatically.    
    405253         *  
    406254         */ 
    407255         
    408         private int headerExtent = 708; 
    409256        public int getHeaderExtent() { 
    410                 return headerExtent; 
    411         } 
    412         public void setHeaderExtent(int headerExtent) { 
    413                 this.headerExtent = headerExtent; 
    414         } 
    415  
    416         private int footerExtent = 1440; //708; 
     257                if (pgMar.getHeader()==null  
     258                                || pgMar.getHeader().intValue() ==0 ) { 
     259                        return 708; 
     260                } else { 
     261                        return pgMar.getHeader().intValue(); 
     262                } 
     263        } 
     264 
    417265        public int getFooterExtent() { 
    418                 return footerExtent; 
    419         } 
    420         public void setFooterExtent(int footerExtent) { 
    421                 this.footerExtent = footerExtent; 
    422         } 
    423          
     266                if (pgMar.getFooter()==null  
     267                                || pgMar.getFooter().intValue() ==0 ) { 
     268                        return 1440; 
     269                } else { 
     270                        return pgMar.getFooter().intValue(); 
     271                } 
     272        } 
    424273         
    425274} 
  • trunk/docx4j/src/main/java/org/docx4j/model/structure/SectionWrapper.java

    r1352 r1567  
    2020package org.docx4j.model.structure; 
    2121 
    22 import java.util.ArrayList; 
    23 import java.util.List; 
    2422 
    2523import org.docx4j.openpackaging.parts.relationships.RelationshipsPart; 
     
    3331                this.headerFooterPolicy = new HeaderFooterPolicy(sectPr, previousHF, rels);  
    3432                 
    35                 page = new PageDimensions(); 
    36                 if (sectPr!=null) { 
    37                         if (sectPr.getPgSz()!=null) { 
    38                                 page.setPageSize(sectPr.getPgSz()); 
    39                         } 
    40                         if (sectPr.getPgMar()!=null) { 
    41                                 page.setMargins(sectPr.getPgMar()); 
    42                         } 
    43                 } 
     33                page = new PageDimensions(sectPr); 
    4434                 
    4535        } 
  • trunk/docx4j/src/main/java/org/docx4j/model/table/TableModel.java

    r1475 r1567  
    9494                cells = new Vector<List<Cell>>(); 
    9595        } 
     96 
     97        // TODO, retire this 
     98        private final static int DEFAULT_PAGE_WIDTH_TWIPS = 12240;  // LETTER; A4 would be 11907 
    9699         
    97100        /** 
     
    427430                        // Default to page width 
    428431                        TblWidth tblWidth = factory.createTblWidth(); 
    429                         tblWidth.setW(BigInteger.valueOf(PageDimensions.DEFAULT_PAGE_WIDTH_TWIPS)); 
     432                        tblWidth.setW(BigInteger.valueOf(DEFAULT_PAGE_WIDTH_TWIPS)); 
     433                                // TODO: shouldn't hard code that.  Pass it in? 
    430434                        tblWidth.setType("dxa"); // twips 
    431435                        tblPr.setTblW(tblWidth);                         
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages/WordprocessingMLPackage.java

    r1536 r1567  
    408408                // Create a basic sectPr using our Page model 
    409409                PageDimensions page = new PageDimensions(); 
     410                page.setPgSize(sz, landscape); 
     411                 
    410412                SectPr sectPr = factory.createSectPr(); 
    411413                body.setSectPr(sectPr); 
    412                 sectPr.setPgSz(PageDimensions.createPgSize(sz, landscape) ); 
    413                 sectPr.setPgMar(page.createPgMar()); 
     414                sectPr.setPgSz(  page.getPgSz() ); 
     415                sectPr.setPgMar( page.getPgMar() ); 
    414416                                 
    415417                // Put the content in the part 
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/parts/DrawingML/CreateDocxWithSmartArt.java

    r1544 r1567  
    6767                        MarginsWellKnown margins,  
    6868                        Document xml) throws Exception { 
    69                  
    70                 // TODO: pass in page size and orientation, 
    71                 // and scale the SmartArt to fill the page. 
    72                                  
     69                                                 
    7370                // Make a basic docx 
    7471                WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(sz, landscape);            
     
    9794 
    9895                // Occupy entire page, less margins 
    99                 PgSz pgSz = PageDimensions.createPgSize(sz, landscape ); 
    10096                PageDimensions pd = new PageDimensions(); 
     97                pd.setPgSize(sz, landscape ); 
     98                PgSz pgSz = pd.getPgSz();  
    10199                pd.setMargins(margins); 
    102                 String cx =  ""+UnitsOfMeasurement.twipToEMU(pgSz.getW().intValue() - (pd.getMarginLeft()+pd.getMarginRight() ) );  //"5486400"; 
    103                 String cy = ""+UnitsOfMeasurement.twipToEMU(pgSz.getH().intValue() - (pd.getMarginTop()+pd.getMarginBottom() ));   //"3200400"; 
     100                String cx =  ""+UnitsOfMeasurement.twipToEMU(pgSz.getW().intValue()  
     101                                - (pd.getPgMar().getLeft().intValue()+pd.getPgMar().getRight().intValue() ) );  //"5486400"; 
     102                String cy = ""+UnitsOfMeasurement.twipToEMU(pgSz.getH().intValue()  
     103                                - (pd.getPgMar().getTop().intValue()+pd.getPgMar().getBottom().intValue() ));   //"3200400"; 
    104104                 
    105105                // Now use it in the docx 
Note: See TracChangeset for help on using the changeset viewer.