Search in sources :

Example 16 with CTP

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP in project poi by apache.

the class XWPFFootnote method init.

private void init() {
    XmlCursor cursor = ctFtnEdn.newCursor();
    //copied from XWPFDocument...should centralize this code
    //to avoid duplication
    cursor.selectPath("./*");
    while (cursor.toNextSelection()) {
        XmlObject o = cursor.getObject();
        if (o instanceof CTP) {
            XWPFParagraph p = new XWPFParagraph((CTP) o, this);
            bodyElements.add(p);
            paragraphs.add(p);
        } else if (o instanceof CTTbl) {
            XWPFTable t = new XWPFTable((CTTbl) o, this);
            bodyElements.add(t);
            tables.add(t);
        } else if (o instanceof CTSdtBlock) {
            XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
            bodyElements.add(c);
        }
    }
    cursor.dispose();
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) XmlCursor(org.apache.xmlbeans.XmlCursor) CTSdtBlock(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)

Example 17 with CTP

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP in project poi by apache.

the class XWPFHeaderFooterPolicy method getWatermarkParagraph.

/*
     * This is the default Watermark paragraph; the only variable is the text message
     * TODO: manage all the other variables
     */
private XWPFParagraph getWatermarkParagraph(String text, int idx) {
    CTP p = CTP.Factory.newInstance();
    byte[] rsidr = doc.getDocument().getBody().getPArray(0).getRsidR();
    byte[] rsidrdefault = doc.getDocument().getBody().getPArray(0).getRsidRDefault();
    p.setRsidP(rsidr);
    p.setRsidRDefault(rsidrdefault);
    CTPPr pPr = p.addNewPPr();
    pPr.addNewPStyle().setVal("Header");
    // start watermark paragraph
    CTR r = p.addNewR();
    CTRPr rPr = r.addNewRPr();
    rPr.addNewNoProof();
    CTPicture pict = r.addNewPict();
    CTGroup group = CTGroup.Factory.newInstance();
    CTShapetype shapetype = group.addNewShapetype();
    shapetype.setId("_x0000_t136");
    shapetype.setCoordsize("1600,21600");
    shapetype.setSpt(136);
    shapetype.setAdj("10800");
    shapetype.setPath2("m@7,0l@8,0m@5,21600l@6,21600e");
    CTFormulas formulas = shapetype.addNewFormulas();
    formulas.addNewF().setEqn("sum #0 0 10800");
    formulas.addNewF().setEqn("prod #0 2 1");
    formulas.addNewF().setEqn("sum 21600 0 @1");
    formulas.addNewF().setEqn("sum 0 0 @2");
    formulas.addNewF().setEqn("sum 21600 0 @3");
    formulas.addNewF().setEqn("if @0 @3 0");
    formulas.addNewF().setEqn("if @0 21600 @1");
    formulas.addNewF().setEqn("if @0 0 @2");
    formulas.addNewF().setEqn("if @0 @4 21600");
    formulas.addNewF().setEqn("mid @5 @6");
    formulas.addNewF().setEqn("mid @8 @5");
    formulas.addNewF().setEqn("mid @7 @8");
    formulas.addNewF().setEqn("mid @6 @7");
    formulas.addNewF().setEqn("sum @6 0 @5");
    CTPath path = shapetype.addNewPath();
    path.setTextpathok(STTrueFalse.T);
    path.setConnecttype(STConnectType.CUSTOM);
    path.setConnectlocs("@9,0;@10,10800;@11,21600;@12,10800");
    path.setConnectangles("270,180,90,0");
    CTTextPath shapeTypeTextPath = shapetype.addNewTextpath();
    shapeTypeTextPath.setOn(STTrueFalse.T);
    shapeTypeTextPath.setFitshape(STTrueFalse.T);
    CTHandles handles = shapetype.addNewHandles();
    CTH h = handles.addNewH();
    h.setPosition("#0,bottomRight");
    h.setXrange("6629,14971");
    CTLock lock = shapetype.addNewLock();
    lock.setExt(STExt.EDIT);
    CTShape shape = group.addNewShape();
    shape.setId("PowerPlusWaterMarkObject" + idx);
    shape.setSpid("_x0000_s102" + (4 + idx));
    shape.setType("#_x0000_t136");
    shape.setStyle("position:absolute;margin-left:0;margin-top:0;width:415pt;height:207.5pt;z-index:-251654144;mso-wrap-edited:f;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin");
    shape.setWrapcoords("616 5068 390 16297 39 16921 -39 17155 7265 17545 7186 17467 -39 17467 18904 17467 10507 17467 8710 17545 18904 17077 18787 16843 18358 16297 18279 12554 19178 12476 20701 11774 20779 11228 21131 10059 21248 8811 21248 7563 20975 6316 20935 5380 19490 5146 14022 5068 2616 5068");
    shape.setFillcolor("black");
    shape.setStroked(STTrueFalse.FALSE);
    CTTextPath shapeTextPath = shape.addNewTextpath();
    shapeTextPath.setStyle("font-family:"Cambria";font-size:1pt");
    shapeTextPath.setString(text);
    pict.set(group);
    // end watermark paragraph
    return new XWPFParagraph(p, doc);
}
Also used : CTR(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR) XWPFParagraph(org.apache.poi.xwpf.usermodel.XWPFParagraph) CTLock(com.microsoft.schemas.office.office.CTLock) CTShape(com.microsoft.schemas.vml.CTShape) CTFormulas(com.microsoft.schemas.vml.CTFormulas) CTPath(com.microsoft.schemas.vml.CTPath) CTTextPath(com.microsoft.schemas.vml.CTTextPath) CTRPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr) CTShapetype(com.microsoft.schemas.vml.CTShapetype) CTHandles(com.microsoft.schemas.vml.CTHandles) CTPPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr) CTH(com.microsoft.schemas.vml.CTH) CTGroup(com.microsoft.schemas.vml.CTGroup) CTPicture(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPicture) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)

Example 18 with CTP

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP in project poi by apache.

the class XWPFFootnote method addNewParagraph.

/**
     * add a new paragraph to the end of the footnote
     *
     * @param paragraph
     * @return the added XWPFParagraph
     */
public XWPFParagraph addNewParagraph(CTP paragraph) {
    CTP newPara = ctFtnEdn.addNewP();
    newPara.set(paragraph);
    XWPFParagraph xPara = new XWPFParagraph(newPara, this);
    paragraphs.add(xPara);
    return xPara;
}
Also used : CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)

Example 19 with CTP

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP in project poi by apache.

the class XWPFHeader method onDocumentRead.

/**
     * reads the document
     *
     * @throws IOException
     */
@Override
protected void onDocumentRead() throws IOException {
    super.onDocumentRead();
    HdrDocument hdrDocument = null;
    InputStream is = null;
    try {
        is = getPackagePart().getInputStream();
        hdrDocument = HdrDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
        headerFooter = hdrDocument.getHdr();
        // parse the document with cursor and add
        // the XmlObject to its lists
        XmlCursor cursor = headerFooter.newCursor();
        cursor.selectPath("./*");
        while (cursor.toNextSelection()) {
            XmlObject o = cursor.getObject();
            if (o instanceof CTP) {
                XWPFParagraph p = new XWPFParagraph((CTP) o, this);
                paragraphs.add(p);
                bodyElements.add(p);
            }
            if (o instanceof CTTbl) {
                XWPFTable t = new XWPFTable((CTTbl) o, this);
                tables.add(t);
                bodyElements.add(t);
            }
            if (o instanceof CTSdtBlock) {
                XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
                bodyElements.add(c);
            }
        }
        cursor.dispose();
    } catch (XmlException e) {
        throw new POIXMLException(e);
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
Also used : HdrDocument(org.openxmlformats.schemas.wordprocessingml.x2006.main.HdrDocument) InputStream(java.io.InputStream) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) POIXMLException(org.apache.poi.POIXMLException) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) XmlCursor(org.apache.xmlbeans.XmlCursor) CTSdtBlock(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)

Example 20 with CTP

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP in project poi by apache.

the class TestXWPFDocument method testAddParagraph.

@Test
public void testAddParagraph() throws IOException {
    XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
    assertEquals(3, doc.getParagraphs().size());
    XWPFParagraph p = doc.createParagraph();
    assertEquals(p, doc.getParagraphs().get(3));
    assertEquals(4, doc.getParagraphs().size());
    assertEquals(3, doc.getParagraphPos(3));
    assertEquals(3, doc.getPosOfParagraph(p));
    CTP ctp = p.getCTP();
    XWPFParagraph newP = doc.getParagraph(ctp);
    assertSame(p, newP);
    XmlCursor cursor = doc.getDocument().getBody().getPArray(0).newCursor();
    XWPFParagraph cP = doc.insertNewParagraph(cursor);
    assertSame(cP, doc.getParagraphs().get(0));
    assertEquals(5, doc.getParagraphs().size());
    doc.close();
}
Also used : CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) XmlCursor(org.apache.xmlbeans.XmlCursor) Test(org.junit.Test)

Aggregations

CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)28 XmlCursor (org.apache.xmlbeans.XmlCursor)12 CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)11 XmlObject (org.apache.xmlbeans.XmlObject)10 Test (org.junit.Test)10 CTPPr (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr)10 CTR (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR)4 CTText (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText)4 BigInteger (java.math.BigInteger)3 CTSdtBlock (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 POIXMLException (org.apache.poi.POIXMLException)2 XWPFHeaderFooterPolicy (org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy)2 XWPFParagraph (org.apache.poi.xwpf.usermodel.XWPFParagraph)2 CTOnOff (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff)2 CTSpacing (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing)2 CTLock (com.microsoft.schemas.office.office.CTLock)1 CTFormulas (com.microsoft.schemas.vml.CTFormulas)1 CTGroup (com.microsoft.schemas.vml.CTGroup)1