Package org.docx4j.wml

Examples of org.docx4j.wml.SectPr


            PPr ppr = ((P) block).getPPr();
            if (ppr == null) {
              ppr = Context.getWmlObjectFactory().createPPr();
              ((P) block).setPPr(ppr);
            }
            SectPr newSectPr = Context.getWmlObjectFactory()
                .createSectPr();
            SectPr.Type type = Context.getWmlObjectFactory()
                .createSectPrType();
            type.setVal("continuous");
            newSectPr.setType(type);

            ppr.setSectPr(newSectPr);
          } else {
            // Equally likely - its a table or something, so add a p
            P newP = Context.getWmlObjectFactory().createP();
            PPr ppr = Context.getWmlObjectFactory().createPPr();
            newP.setPPr(ppr);

            SectPr newSectPr = Context.getWmlObjectFactory()
                .createSectPr();
            SectPr.Type type = Context.getWmlObjectFactory()
                .createSectPrType();
            type.setVal("continuous");
            newSectPr.setType(type);
            ppr.setSectPr(newSectPr);

            bodyChildren.add(indexIntoBody.intValue(), newP); // add
                                      // before
                                      // altChunk
View Full Code Here


      // in the first section
     
      hfTemplates = new HashMap<CTRel, JaxbXmlPart>();
     
      SectionWrapper sw = input.getDocumentModel().getSections().get(0);
      SectPr sectPr = sw.getSectPr();
     
      List<CTRel> hdrFtrRefs = sectPr.getEGHdrFtrReferences();
      titlePage = sectPr.getTitlePg();
     
      for (CTRel rel : hdrFtrRefs) {
        String relId = rel.getId();
        log.debug("for h|f relId: " + relId);
       
        JaxbXmlPart part = (JaxbXmlPart)input.getMainDocumentPart().getRelationshipsPart().getPart(relId);
        FieldsPreprocessor.complexifyFields(part );
       
        log.debug("complexified: " + XmlUtils.marshaltoString(part.getJaxbElement(), true));
       
        hfTemplates.put(rel, part);
      }
    }
   
    // Create WordprocessingMLPackage target, by cloning
    OpcPackage result = null;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    SaveToZipFile saver = new SaveToZipFile(input);
    saver.save(baos);
    byte[] template = baos.toByteArray();
    WordprocessingMLPackage target = WordprocessingMLPackage.load(
        new ByteArrayInputStream(template));
   
   
    // populate main document part
    SectPr documentSeparator = getDocumentSeparator(target);
    if (processHeadersAndFooters) {
      if (titlePage!=null
          && titlePage.isVal()) {
        documentSeparator.setTitlePg(titlePage);
      }
      documentSeparator.getEGHdrFtrReferences().clear();
    }
    target.getMainDocumentPart().getContent().clear();
   
    /*
     * What we're doing, effectively, is doing the
     * main content in a single hit (ie for all
     * instances), and then, for each instance,
     * doing the headers/footers.
     *
     * It is this way because that is how the code
     * has evolved.
     *
     * Since we have to do the headers/footers
     * instance by instance, it would probably
     * be neater to do the main content at
     * the same time (ie instead of using
     * performOverList at the start of this method).
     */
   
    int i = 0;
    for (List<Object> content : mdpResults) {
     
           
      // now inject the content
      target.getMainDocumentPart().getContent().addAll(content);

      log.debug(XmlUtils.marshaltoString(target.getMainDocumentPart().getJaxbElement(), true, true) );
     
      // add sectPr to final paragraph
      Object last = content.get( content.size()-1);
      P lastP = null;
      if (last instanceof P) {
        lastP = (P)last;
      } else {
        lastP = Context.getWmlObjectFactory().createP();
        target.getMainDocumentPart().getContent().add(lastP)
      }
      if (lastP.getPPr()==null) {
        lastP.setPPr(Context.getWmlObjectFactory().createPPr());       
      }
      SectPr thisSection = XmlUtils.deepCopy(documentSeparator);
      lastP.getPPr().setSectPr(thisSection);
     
      if (processHeadersAndFooters) {
        for( CTRel ctRel : hfTemplates.keySet()) {
         
          // Create a suitable part
          JaxbXmlPart part = hfTemplates.get(ctRel);
          JaxbXmlPart clonedPart = null;
          if (part instanceof HeaderPart) {
            clonedPart = new HeaderPart();
            clonedPart.setJaxbElement(Context.getWmlObjectFactory().createHdr());
          } else if (part instanceof FooterPart) {
            clonedPart = new FooterPart();
            clonedPart.setJaxbElement(Context.getWmlObjectFactory().createFtr());
          }
         
          // Populate it
          List<Object> newContent = performOnInstance(input,
              ((ContentAccessor)part).getContent(),
              data.get(i), formTextFieldNames )
          ((ContentAccessor)clonedPart).getContent().addAll(newContent);
         
          // Add it
          Relationship rel = target.getMainDocumentPart().addTargetPart(clonedPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);
         
          // Now add CTRel!
          CTRel newHfRef = XmlUtils.deepCopy(ctRel);
          newHfRef.setId(rel.getId());
         
          thisSection.getEGHdrFtrReferences().add(newHfRef);
         
        }
      }
      i++;
    }
View Full Code Here

   * @param template
   * @return
   */
  private static SectPr getDocumentSeparator(WordprocessingMLPackage template) {
       
       SectPr sectPr = template.getMainDocumentPart().getJaxbElement().getBody().getSectPr();
      
       if (sectPr==null) {
         // Maybe the last P already contains one?
         // Presumably Word would reuse this.
         List all = template.getMainDocumentPart().getContent();
          Object last = all.get( all.size()-1 );
          if (last instanceof P) {
            if (((P) last).getPPr()!=null
                && ((P) last).getPPr().getSectPr() !=null) {
              sectPr = ((P) last).getPPr().getSectPr();
            }
          }        
       }
      
       if (sectPr==null) {
        
        // Create a basic sectPr using our Page model
        String papersize= Docx4jProperties.getProperties().getProperty("docx4j.PageSize", "A4");
        log.info("Using paper size: " + papersize);
       
        String landscapeString = Docx4jProperties.getProperties().getProperty("docx4j.PageOrientationLandscape", "false");
        boolean landscape= Boolean.parseBoolean(landscapeString);
        log.info("Landscape orientation: " + landscape);
       
        PageDimensions page = new PageDimensions();
        page.setPgSize(PageSizePaper.valueOf(papersize), landscape);
       
        sectPr = Context.getWmlObjectFactory().createSectPr();
        sectPr.setPgSzpage.getPgSz() );
        sectPr.setPgMar( page.getPgMar() );       
       }
      
       // <w:pgNumType w:start="1"/>
       CTPageNumber pageNumber = sectPr.getPgNumType();
       if (pageNumber==null) {
         pageNumber = Context.getWmlObjectFactory().createCTPageNumber();
         sectPr.setPgNumType(pageNumber);
       }
       pageNumber.setStart(BigInteger.ONE);
      
       return sectPr;
    
View Full Code Here

    }
   
    Object o = body.getContent().get(0);
   
    if (o instanceof P) {
      SectPr sectPr = cutSectPr((P)o);
     
      if (sectPr!=null) {
        pasteSectPr(body.getContent(), sectPr);
        log.info("Moved sectPr to new P");
        return;
      }
     
    } else if (o instanceof SdtElement) {
      Object o2 = ((SdtElement)o).getSdtContent().getContent().get(0);
     
      if (o2!=null && o2 instanceof P) {

        SectPr sectPr = cutSectPr((P)o2);
       
        if (sectPr!=null) {
          pasteSectPr(((SdtElement)o).getSdtContent().getContent(), sectPr);
          log.info("Moved sectPr to new P inside content control");
          return;
View Full Code Here

  private static  SectPr cutSectPr(P p) {
   
    if (p.getPPr()!=null
        && p.getPPr().getSectPr()!=null) {
     
      SectPr sectPr = p.getPPr().getSectPr();
      p.getPPr().setSectPr(null);
      return sectPr;
     
    }
    return null;
View Full Code Here

             * 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
View Full Code Here

            && ((P) last).getPPr()!=null
              && ((P) last).getPPr().getSectPr() !=null) {
            // ok
        log.debug(".. but last p contains sectPr .. move it"); // so our assumption later about there being a following section is correct

        SectPr thisSectPr = ((P) last).getPPr().getSectPr();
        document.getBody().setSectPr(thisSectPr);
        ((P) last).getPPr().setSectPr(null);
        sectPrs.remove(thisSectPr);
       
        } else {     
View Full Code Here

    List mainContent = output.getMainDocumentPart().getContent();
   
    // Add a sectPr   
    org.docx4j.wml.P  par = objectFactory.createP();
    mainContent.add(0,par);
    SectPr sectPr = objectFactory.createSectPr();
    PPr ppr = objectFactory.createPPr();
    ppr.setSectPr(sectPr);
    par.setPPr(ppr);
   
   
    // From the spec, if this element is set to true and the
    // first page header type is omitted, then a blank header
    // shall be created as needed
    sectPr.setTitlePg(new BooleanDefaultTrue());
   
    // Set nextPage on the *next* (!) section
//    output.getDocumentModel().refresh();
//    List<SectionWrapper> sections = output.getDocumentModel().getSections();
//    SectPr nextSectPr = sections.get(1).getSectPr();
View Full Code Here

      Relationship relationship )
      throws InvalidFormatException {

    List<SectionWrapper> sections = wordprocessingMLPackage.getDocumentModel().getSections();
      
    SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
    // There is always a section wrapper, but it might not contain a sectPr
    if (sectPr==null ) {
      sectPr = factory.createSectPr();
      wordprocessingMLPackage.getMainDocumentPart().addObject(sectPr);
      sections.get(sections.size() - 1).setSectPr(sectPr);
    }

    HeaderReference headerReference = factory.createHeaderReference();
    headerReference.setId(relationship.getId());
    headerReference.setType(HdrFtrRef.DEFAULT);
    sectPr.getEGHdrFtrReferences().add(headerReference);

  }
View Full Code Here

   
    // Create a basic sectPr using our Page model
    PageDimensions page = new PageDimensions();
    page.setPgSize(sz, landscape);
   
    SectPr sectPr = factory.createSectPr();
    body.setSectPr(sectPr);
    sectPr.setPgSzpage.getPgSz() );
    sectPr.setPgMar( page.getPgMar() );
       
    // Put the content in the part
    wordDocumentPart.setJaxbElement(wmlDocumentEl);
           
    // Add the main document part to the package relationships
View Full Code Here

TOP

Related Classes of org.docx4j.wml.SectPr

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.