Package org.docx4j.convert.out.common

Examples of org.docx4j.convert.out.common.ConversionSectionWrapper


   * @return
   */
  protected boolean checkRequires2Pass() {
  boolean ret = false;
  boolean sectionPagesUsed = false;
  ConversionSectionWrapper wrapper = null;
  List<ConversionSectionWrapper> wrapperList = getSections().getList();
    for (int i=0; (!ret) && (i < wrapperList.size()); i++) {
      wrapper = wrapperList.get(i);
      if (wrapper.getPageNumberInformation().getPageStart() > -1) {
        ret = ((i == 0) && (wrapper.getPageNumberInformation().getPageStart() != 1)) ||
            (i > 0);
      }
      if (wrapper.getPageNumberInformation().isSectionpagesPresent()) {
        sectionPagesUsed = true;
      }
    }
    return (ret || ((sectionPagesUsed) && (wrapperList.size() > 1)));
  }
View Full Code Here


  private static LayoutMasterSet getFoLayoutMasterSet(AbstractWmlConversionContext context) {
   
   
    LayoutMasterSet lms = getFactory().createLayoutMasterSet();
    List<ConversionSectionWrapper> sections = context.getSections().getList();
    ConversionSectionWrapper section = null;
   
    for(int i=0; i<sections.size(); i++) {
     
      section = sections.get(i);
      HeaderFooterPolicy hf = section.getHeaderFooterPolicy();
      String sectionName = "s" + Integer.toString(i + 1);
     
      // FIRST, create simple-page-masters
      // has first header or footer?
      if (hf.getFirstHeader()!=null || hf.getFirstFooter()!=null) {
        // per spec, HeaderFooterPolicy checks the titlePg elememt
       
        lms.getSimplePageMasterOrPageSequenceMaster().add(
          createSimplePageMaster(sectionName + "-firstpage",
              section.getPageDimensions(),
              "firstpage",
            (hf.getFirstHeader()!=null),
            (hf.getFirstFooter()!=null) ));
      }
     
      // has even or odd header or footer?
        /*
         *       <w:headerReference w:type="even" r:id="rId12"/>
         *       <w:headerReference w:type="default" r:id="rId13"/>
         *      
         *       the default one is treated as odd.
         */
      if (hf.getEvenHeader()!=null || hf.getEvenFooter()!=null) {
       
        lms.getSimplePageMasterOrPageSequenceMaster().add(
          createSimplePageMaster(sectionName + "-evenpage"
              section.getPageDimensions(),
              "evenpage",
            (hf.getEvenHeader()!=null),
            (hf.getEvenFooter()!=null) ));
       
        // the xslt outputs a "-default" page as the odd-page
      }
     
      if (hf.getDefaultHeader()!=null
          || hf.getDefaultFooter()!=null) {
       
        lms.getSimplePageMasterOrPageSequenceMaster().add(
          createSimplePageMaster(sectionName + "-default"
              section.getPageDimensions(),
              "default",
            (hf.getDefaultHeader()!=null),
            (hf.getDefaultFooter()!=null) ));       
      }

      // simple: no headers and footers - after the first page anyway/
      // We still need this where there is just a first page header/footer,
      // since otherwise there'd be no page sequence for any content
      // after the first page, and you'd get:
      //    org.apache.fop.fo.pagination.PageProductionException:
      //    Subsequences exhausted in page-sequence-master ..., cannot recover.
      //
      // <w:sectPr>
      //   <w:headerReference w:type="first" r:id="rId7"/>
      // </w:sectPr>     
      if (
        (hf.getDefaultHeader() == null) && (hf.getDefaultFooter() == null)) {
        lms.getSimplePageMasterOrPageSequenceMaster().add(
            createSimplePageMaster(sectionName + "-simple"
                section.getPageDimensions(),
                "simple",
              true, true));
      }
     
      // SECOND, create page-sequence-masters
View Full Code Here

  protected List<SectionPageInformation> createPageNumberInformation(FOConversionContext conversionContext) {
   
    List<ConversionSectionWrapper> wrapperList = null;
    List<FORenderer.SectionPageInformation> ret = Collections.EMPTY_LIST;
    ConversionSectionWrapper section = null;
    String sectionId = null;
    String pageFoFormat = null;
    String pageWordFormat = null;
    FORenderer.SectionPageInformation pageNumberInformation = null;
 
    if (conversionContext.isRequires2Pass()) {
      wrapperList = conversionContext.getSections().getList();
      ret = new ArrayList<FORenderer.SectionPageInformation>(wrapperList.size());
      for (int i=0; i<wrapperList.size(); i++) {
        section = wrapperList.get(i);
        pageWordFormat = section.getPageNumberInformation().getPageFormat();
        pageFoFormat = FormattingSwitchHelper.getFoPageNumberFormat(pageWordFormat);
        /* The format used for the document and section page count corresponds to the
         * one defined for the page number format. If some other format has been defined
         * in the NUMPAGES (section.getPageNumberInformation().getNumpagesFormat()) or
         * in the SECTIONPAGES (section.getPageNumberInformation().getSectionpagesFormat())
         * this format is ignored here. This is done, so that the look is consistent with
         * the 1 pass conversion, where fo formats the fo:page-number-citation-last according
         * the page number format.
         */
        sectionId = section.getId();
        if (pageFoFormat == null) {
          pageFoFormat = FoNumberFormatUtil.FO_PAGENUMBER_DECIMAL;
        }
        pageNumberInformation =
            new FoSectionPageInformation(
View Full Code Here

  protected static List<ConversionSectionWrapper> processDummy(WordprocessingMLPackage wmlPackage, Document document, RelationshipsPart rels, BooleanDefaultTrue evenAndOddHeaders, boolean dummyPageNumbering) {
   
    log.debug("starting");
   
    List<ConversionSectionWrapper> conversionSections = new ArrayList<ConversionSectionWrapper>();
    ConversionSectionWrapper currentSectionWrapper = null;
    HeaderFooterPolicy previousHF =
        new HeaderFooterPolicy(document.getBody().getSectPr(), null, rels, evenAndOddHeaders);
 
    // SectionWrapper does work where sectPr is null (ie document has no body level sectPr),
    // so document.getBody().getSectPr() is ok
View Full Code Here

  protected static ConversionSectionWrapper createSectionWrapper(
      SectPr sectPr, HeaderFooterPolicy headerFooterPolicy, RelationshipsPart rels, BooleanDefaultTrue evenAndOddHeaders,
      int conversionSectionIndex, List<Object> content,
      boolean dummyPageNumbering) {
   
    ConversionSectionWrapper csw =
          new ConversionSectionWrapper(sectPr, headerFooterPolicy, rels, evenAndOddHeaders,
          "s" + Integer.toString(conversionSectionIndex), content);
   
    PageNumberInformation pageNumberInformation =
        PageNumberInformationCollector.process(csw, dummyPageNumbering);
    csw.setPageNumberInformation(pageNumberInformation);
   
    return csw;
  }
View Full Code Here

    removeContentControls( document);
    List<SectPr> sectPrs =  getSectPrs(document);

    // Local vars
    List<ConversionSectionWrapper> conversionSections = new ArrayList<ConversionSectionWrapper>();
    ConversionSectionWrapper currentSectionWrapper = null;
    HeaderFooterPolicy previousHF = null;
    int conversionSectionIndex = 0;
    List<Object> sectionContent = new ArrayList<Object>();
   
    // Now go through the document content,
   
    int sectPrIndex = 0; // includes continuous ones
    for (Object o : document.getBody().getContent() ) {
     
      if (o instanceof org.docx4j.wml.P) {
       
        if (((org.docx4j.wml.P)o).getPPr() != null ) {
         
          org.docx4j.wml.PPr ppr = ((org.docx4j.wml.P)o).getPPr();
          if (ppr.getSectPr()!=null) {

            /* If the *following* section is continuous,
             * don't add *this* section, because we want our
             * sectionWrapper to surround the content preceding
             * both sectPr.
             *
             * When we do eventually create that section wrapper,
             * it must use the header/footer settings from
             * *this* section.
             *
             * There is a special case to consider:
             * 
                    <w:sectPr>
                      <w:type w:val="continuous"/>
                      <w:pgSz <---- different values from previous sectPr
             *
             * In this case, Word will render a page break,
             * but:
             * 1. still show it as continuous
             * 2. still use the headers/footers from this section
             * 
             */
           
            boolean ignoreThisSection = false;
            SectPr followingSectPr = sectPrs.get(++sectPrIndex);
            if ( followingSectPr.getType()!=null
                     && followingSectPr.getType().getVal().equals("continuous")) {

              log.info("following sectPr is continuous; this section wrapper must include its contents ");
              ignoreThisSection = true;
             
            }
           
           
            if (ignoreThisSection) {
              // In case there are some headers/footers that apply to both this content and the
              // content before the continuous sectPr,
              // or that need to get inherited by the section after the continuous sectPr
              previousHF = new HeaderFooterPolicy(ppr.getSectPr(), previousHF, rels, evenAndOddHeaders);

             
              PgSz pgSzThis = ppr.getSectPr().getPgSz();
              PgSz pgSzNext = followingSectPr.getPgSz();
              if (insertPageBreak( pgSzThis,  pgSzNext)) {
               
                ppr.setPageBreakBefore(new BooleanDefaultTrue());
              }
              //ppr.setSectPr(null); // Don't do this, since we have to process the docx (inc sectPrs) multiple times for a single PDF output
             
            } else {
              currentSectionWrapper = createSectionWrapper(
                  ppr.getSectPr(), previousHF, rels, evenAndOddHeaders,
                  ++conversionSectionIndex, sectionContent, dummyPageNumbering);    
              conversionSections.add(currentSectionWrapper);
              previousHF = currentSectionWrapper.getHeaderFooterPolicy();
              sectionContent = new ArrayList<Object>();
             
            }
          }
        }       
View Full Code Here

     * @param footerBpda
     */
    static void adjustLayoutMasterSet(LayoutMasterSet layoutMasterSet, ConversionSectionWrappers conversionSectionWrappers, Map<String, Integer> headerBpda, Map<String, Integer> footerBpda) {
     
    List<ConversionSectionWrapper> sections = conversionSectionWrappers.getList();
    ConversionSectionWrapper section = null;
     
      for (Object o : layoutMasterSet.getSimplePageMasterOrPageSequenceMaster()) {
       
        if (o instanceof SimplePageMaster) {
         
View Full Code Here

//    String width = props.get("width");
//    String height = props.get("height");

   
    // How to get current page width??
    ConversionSectionWrapper csw = context.getSections().getCurrentSection();
    PageDimensions pageDimensions = csw.getPageDimensions();
   
    // pgSz.getW().intValue() - (pgMar.getLeft().intValue() + pgMar.getRight().intValue());
    int writableWidthTwips = pageDimensions.getWritableWidthTwips();
    float writableWidthPts = writableWidthTwips/20;
    int writableHeightTwips = pageDimensions.getWritableHeightTwips();
View Full Code Here

TOP

Related Classes of org.docx4j.convert.out.common.ConversionSectionWrapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.