Search in sources :

Example 6 with CTPPr

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr 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 7 with CTPPr

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

the class TestXWPFParagraph method testSetGetSpacingLineRule.

@Test
public void testSetGetSpacingLineRule() throws IOException {
    XWPFDocument doc = new XWPFDocument();
    XWPFParagraph p = doc.createParagraph();
    CTP ctp = p.getCTP();
    CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
    assertEquals(STLineSpacingRule.INT_AUTO, p.getSpacingLineRule().getValue());
    CTSpacing spacing = ppr.addNewSpacing();
    spacing.setLineRule(STLineSpacingRule.AT_LEAST);
    assertEquals(LineSpacingRule.AT_LEAST, p.getSpacingLineRule());
    p.setSpacingAfter(100);
    assertEquals(100, spacing.getAfter().intValue());
    doc.close();
}
Also used : CTPPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr) CTSpacing(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) Test(org.junit.Test)

Example 8 with CTPPr

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

the class TestXWPFParagraph method testSetGetWordWrap.

@Test
public void testSetGetWordWrap() throws IOException {
    XWPFDocument doc = new XWPFDocument();
    XWPFParagraph p = doc.createParagraph();
    CTP ctp = p.getCTP();
    CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
    CTOnOff wordWrap = ppr.addNewWordWrap();
    wordWrap.setVal(STOnOff.FALSE);
    assertEquals(false, p.isWordWrap());
    p.setWordWrapped(true);
    assertEquals(STOnOff.TRUE, ppr.getWordWrap().getVal());
    doc.close();
}
Also used : CTPPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr) CTOnOff(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) Test(org.junit.Test)

Example 9 with CTPPr

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

the class TestXWPFParagraph method testSetGetAlignment.

@Test
public void testSetGetAlignment() throws IOException {
    //new clean instance of paragraph
    XWPFDocument doc = new XWPFDocument();
    XWPFParagraph p = doc.createParagraph();
    assertEquals(STJc.LEFT.intValue(), p.getAlignment().getValue());
    CTP ctp = p.getCTP();
    CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
    CTJc align = ppr.addNewJc();
    align.setVal(STJc.CENTER);
    assertEquals(ParagraphAlignment.CENTER, p.getAlignment());
    p.setAlignment(ParagraphAlignment.BOTH);
    assertEquals(STJc.BOTH, ppr.getJc().getVal());
    doc.close();
}
Also used : CTJc(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc) CTPPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) Test(org.junit.Test)

Example 10 with CTPPr

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

the class TestXWPFParagraph method testSetGetBorderTop.

@Test
public void testSetGetBorderTop() throws IOException {
    //new clean instance of paragraph
    XWPFDocument doc = new XWPFDocument();
    XWPFParagraph p = doc.createParagraph();
    assertEquals(STBorder.NONE.intValue(), p.getBorderTop().getValue());
    CTP ctp = p.getCTP();
    CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
    //bordi
    CTPBdr bdr = ppr.addNewPBdr();
    CTBorder borderTop = bdr.addNewTop();
    borderTop.setVal(STBorder.DOUBLE);
    bdr.setTop(borderTop);
    assertEquals(Borders.DOUBLE, p.getBorderTop());
    p.setBorderTop(Borders.SINGLE);
    assertEquals(STBorder.SINGLE, borderTop.getVal());
    doc.close();
}
Also used : CTPPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr) CTBorder(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder) CTPBdr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPBdr) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) Test(org.junit.Test)

Aggregations

CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)11 CTPPr (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr)10 Test (org.junit.Test)8 BigInteger (java.math.BigInteger)3 CTOnOff (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff)2 CTR (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR)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 CTH (com.microsoft.schemas.vml.CTH)1 CTHandles (com.microsoft.schemas.vml.CTHandles)1 CTPath (com.microsoft.schemas.vml.CTPath)1 CTShape (com.microsoft.schemas.vml.CTShape)1 CTShapetype (com.microsoft.schemas.vml.CTShapetype)1 CTTextPath (com.microsoft.schemas.vml.CTTextPath)1 XWPFParagraph (org.apache.poi.xwpf.usermodel.XWPFParagraph)1 CTBorder (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder)1 CTHdrFtr (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr)1 CTInd (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd)1