Package org.apache.poi.xwpf.model

Examples of org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy


      POIXMLTextExtractor extractor = (POIXMLTextExtractor) ExtractorFactory.createExtractor(bis);
      POIXMLDocument document = extractor.getDocument();
     
      if (document instanceof XWPFDocument) {
        XWPFDocument xDocument = (XWPFDocument) document;
        XWPFHeaderFooterPolicy hfPolicy = xDocument.getHeaderFooterPolicy();
        extractHeaders(buffy, hfPolicy);
        extractContent(buffy, xDocument);
        extractFooters(buffy, hfPolicy);
      }
View Full Code Here


      CTSectPr ctSectPr = null;
      if (paragraph.getCTP().getPPr() != null) {
        ctSectPr = paragraph.getCTP().getPPr().getSectPr();
      }

      XWPFHeaderFooterPolicy headerFooterPolicy = null;
      if (ctSectPr != null) {
        headerFooterPolicy = new XWPFHeaderFooterPolicy(document, ctSectPr);
        extractHeaders(buffy, headerFooterPolicy);
      }

      XWPFParagraphDecorator decorator = new XWPFCommentsDecorator(new XWPFHyperlinkDecorator(paragraph, null, true));
View Full Code Here

       assertEquals(null, run.getCTR().getRPr());
    }

    public void testPictureInHeader() {
        XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerPic.docx");
        XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();

        XWPFHeader header = policy.getDefaultHeader();

        int count = 0;

        for (XWPFParagraph p : header.getParagraphs()) {
            for (XWPFRun r : p.getRuns()) {
View Full Code Here

            }
            cursor.dispose();
     
            // Sort out headers and footers
      if (doc.getDocument().getBody().getSectPr() != null)
        headerFooterPolicy = new XWPFHeaderFooterPolicy(this);
       
      // Create for each XML-part in the Package a PartClass
            for(POIXMLDocumentPart p : getRelations()){
                String relation = p.getPackageRelationship().getRelationshipType();
                if(relation.equals(XWPFRelation.STYLES.getRelation())){
View Full Code Here

public final class TestXWPFHeader extends TestCase {

  public void testSimpleHeader() {
    XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerFooter.docx");

    XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();


    XWPFHeader header = policy.getDefaultHeader();
    XWPFFooter footer = policy.getDefaultFooter();
    assertNotNull(header);
    assertNotNull(footer);

    // TODO verify if the following is correct
    assertNull(header.toString());
View Full Code Here

  }

  public void testSetHeader() throws IOException {
    XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
    // no header is set (yet)
    XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
    assertNull(policy.getDefaultHeader());
    assertNull(policy.getFirstPageHeader());
    assertNull(policy.getDefaultFooter());

    CTP ctP1 = CTP.Factory.newInstance();
    CTR ctR1 = ctP1.addNewR();
    CTText t = ctR1.addNewT();
    t.setStringValue("Paragraph in header");

    // Commented MB 23 May 2010
    //CTP ctP2 = CTP.Factory.newInstance();
    //CTR ctR2 = ctP2.addNewR();
    //CTText t2 = ctR2.addNewT();
    //t2.setStringValue("Second paragraph.. for footer");
   
    // Create two paragraphs for insertion into the footer.
    // Previously only one was inserted MB 23 May 2010
    CTP ctP2 = CTP.Factory.newInstance();
    CTR ctR2 = ctP2.addNewR();
    CTText t2 = ctR2.addNewT();
    t2.setStringValue("First paragraph for the footer");
   
    CTP ctP3 = CTP.Factory.newInstance();
    CTR ctR3 = ctP3.addNewR();
    CTText t3 = ctR3.addNewT();
    t3.setStringValue("Second paragraph for the footer");

    XWPFParagraph p1 = new XWPFParagraph(ctP1, sampleDoc);
    XWPFParagraph[] pars = new XWPFParagraph[1];
    pars[0] = p1;

    XWPFParagraph p2 = new XWPFParagraph(ctP2, sampleDoc);
    XWPFParagraph p3 = new XWPFParagraph(ctP3, sampleDoc);
    XWPFParagraph[] pars2 = new XWPFParagraph[2];
    pars2[0] = p2;
    pars2[1] = p3;

    // Set headers
    policy.createHeader(policy.DEFAULT, pars);
    policy.createHeader(policy.FIRST);
    // Set a default footer and capture the returned XWPFFooter object.
    XWPFFooter footer = policy.createFooter(policy.DEFAULT, pars2);

    // Ensure the headers and footer were set correctly....
    assertNotNull(policy.getDefaultHeader());
    assertNotNull(policy.getFirstPageHeader());
    assertNotNull(policy.getDefaultFooter());
    // ....and that the footer object captured above contains two
    // paragraphs of text.
    assertEquals(2, footer.getParagraphs().size());
   
    // As an additional check, recover the defauls footer and
    // make sure that it contains two paragraphs of text and that
    // both do hold what is expected.
    footer = policy.getDefaultFooter();

    XWPFParagraph[] paras = new XWPFParagraph[footer.getParagraphs().size()];
    int i=0;
    for(XWPFParagraph p : footer.getParagraphs()) {
       paras[i++] = p;
View Full Code Here

  }

  public void testSetWatermark() {
    XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
    // no header is set (yet)
    XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
    assertNull(policy.getDefaultHeader());
    assertNull(policy.getFirstPageHeader());
    assertNull(policy.getDefaultFooter());

    policy.createWatermark("DRAFT");

    assertNotNull(policy.getDefaultHeader());
    assertNotNull(policy.getFirstPageHeader());
    assertNotNull(policy.getEvenPageHeader());
  }
View Full Code Here

    System.out.println(extractor.getText());
  }
 
  public String getText() {
    StringBuffer text = new StringBuffer();
    XWPFHeaderFooterPolicy hfPolicy = document.getHeaderFooterPolicy();
   
    // Start out with all headers
    // TODO - put them in where they're needed
    if(hfPolicy.getFirstPageHeader() != null) {
      text.append( hfPolicy.getFirstPageHeader().getText() );
    }
    if(hfPolicy.getEvenPageHeader() != null) {
      text.append( hfPolicy.getEvenPageHeader().getText() );
    }
    if(hfPolicy.getDefaultHeader() != null) {
      text.append( hfPolicy.getDefaultHeader().getText() );
    }
   
    // First up, all our paragraph based text
    Iterator<XWPFParagraph> i = document.getParagraphsIterator();
    while(i.hasNext()) {
      XWPFParagraphDecorator decorator = new XWPFCommentsDecorator(
          new XWPFHyperlinkDecorator(i.next(), null, fetchHyperlinks));
      text.append(decorator.getText()+"\n");
    }

    // Then our table based text
    Iterator<XWPFTable> j = document.getTablesIterator();
    while(j.hasNext()) {
      text.append(j.next().getText()+"\n");
    }
   
    // Finish up with all the footers
    // TODO - put them in where they're needed
    if(hfPolicy.getFirstPageFooter() != null) {
      text.append( hfPolicy.getFirstPageFooter().getText() );
    }
    if(hfPolicy.getEvenPageFooter() != null) {
      text.append( hfPolicy.getEvenPageFooter().getText() );
    }
    if(hfPolicy.getDefaultFooter() != null) {
      text.append( hfPolicy.getDefaultFooter().getText() );
    }
   
    return text.toString();
  }
View Full Code Here

            for(CTTbl table : body.getTblArray()) {
                tables.add(new XWPFTable(table));
            }

            // Sort out headers and footers
            headerFooterPolicy = new XWPFHeaderFooterPolicy(this);

            for(POIXMLDocumentPart p : getRelations()){
                String relation = p.getPackageRelationship().getRelationshipType();
                if(relation.equals(XWPFRelation.COMMENT.getRelation())){
                    CommentsDocument cmntdoc = CommentsDocument.Factory.parse(p.getPackagePart().getInputStream());
View Full Code Here

     * @see org.apache.poi.xwpf.extractor.XWPFWordExtractor#getText()
     */
    @Override
    protected void buildXHTML(XHTMLContentHandler xhtml)
            throws SAXException, XmlException, IOException {
        XWPFHeaderFooterPolicy hfPolicy = document.getHeaderFooterPolicy();

        // headers
        if (hfPolicy!=null) {
            extractHeaders(xhtml, hfPolicy);
        }
View Full Code Here

TOP

Related Classes of org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy

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.