docx4j文本框边框内部边距

时间:2019-02-18 14:18:56

标签: java ms-word docx4j

sample output of my code but I need to remove internal borders

我要删除文本区域中的填充,如所附图片中创建文本区域段落的功能所示。我做了很多尝试,以在样式中添加填充,但这是行不通的。

public static P pTextBox(List<String> lines, float boxHeight, float boxWidth, float top, float left, Integer font) {
    org.docx4j.wml.ObjectFactory wmlObjectFactory = Context.getWmlObjectFactory();
    P p = wmlObjectFactory.createP();
    Jc justification = wmlObjectFactory.createJc();
    justification.setVal(JcEnumeration.RIGHT);
    // Create object for r
    R r = wmlObjectFactory.createR();
    p.getContent().add(r);
    // Create object for rPr
    RPr rpr = wmlObjectFactory.createRPr();
    r.setRPr(rpr);
    // Create object for noProof
    BooleanDefaultTrue booleandefaulttrue = wmlObjectFactory.createBooleanDefaultTrue();
    rpr.setNoProof(booleandefaulttrue);
    // Create object for pict (wrapped in JAXBElement)
    Pict pict = wmlObjectFactory.createPict();
    JAXBElement<org.docx4j.wml.Pict> pictWrapped = wmlObjectFactory.createRPict(pict);
    r.getContent().add(pictWrapped);
    org.docx4j.vml.ObjectFactory vmlObjectFactory = new org.docx4j.vml.ObjectFactory();
    // Create object for shape (wrapped in JAXBElement)
    org.docx4j.vml.CTRect shape = vmlObjectFactory.createCTRect();
    shape.setCliptowrap(STTrueFalse.T);
    // shape.setStyle("position:absolute;margin-left:0;margin-top:0;width:186pt;height:110.25pt;z-index:-251657216;visibility:visible;mso-wrap-style:square;mso-width-percent:400;mso-height-percent:200;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:center;mso-position-horizontal-relative:text;mso-position-vertical:absolute;mso-position-vertical-relative:text;mso-width-percent:400;mso-height-percent:200;mso-width-relative:margin;mso-height-relative:margin;v-text-anchor:top");
    JAXBElement<org.docx4j.vml.CTRect> shapeWrapped = vmlObjectFactory.createRect(shape);
    pict.getAnyAndAny().add(shapeWrapped);
    // Create object for textbox (wrapped in JAXBElement)
    CTTextbox textbox = vmlObjectFactory.createCTTextbox();

    // textbox.setStyle( "mso-fit-shape-to-text:t");
    // textbox.setStyle("position:absolute;margin-left:0;margin-top:0;width:186pt;height:110.25pt;z-index:-251657216;visibility:visible;mso-wrap-style:square;mso-width-percent:400;mso-height-percent:200;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:center;mso-position-horizontal-relative:text;mso-position-vertical:absolute;mso-position-vertical-relative:text;mso-width-percent:400;mso-height-percent:200;mso-width-relative:margin;mso-height-relative:margin;v-text-anchor:top");
    textbox.setInsetmode(org.docx4j.vml.officedrawing.STInsetMode.CUSTOM);

    JAXBElement<org.docx4j.vml.CTTextbox> textboxWrapped = vmlObjectFactory.createTextbox(textbox);

    shape.getEGShapeElements().add(textboxWrapped);
    // Create object for txbxContent
    org.docx4j.wml.CTTxbxContent txbxcontent = wmlObjectFactory.createCTTxbxContent();
    textbox.setTxbxContent(txbxcontent);
    // Create object for p
    org.docx4j.wml.P p2 = wmlObjectFactory.createP();
    txbxcontent.getContent().add(p2);
    // Create object for pPr
    org.docx4j.wml.PPr pprText = wmlObjectFactory.createPPr();
    pprText.setJc(justification);
    org.docx4j.wml.PPr ppr2 = wmlObjectFactory.createPPr();
    ppr2.setJc(justification);
    // SPACING
    PPrBase.Spacing pprbase = wmlObjectFactory.createPPrBaseSpacing();
    pprbase.setBefore(BigInteger.valueOf(0));
    pprbase.setAfter(BigInteger.valueOf(0));
    pprbase.setLine(BigInteger.valueOf(0));
    // pprbase.setLineRule(STLineSpacingRule.);
    ppr2.setSpacing(pprbase);
    // pprText.setSpacing(pprbase);

    // PPrBase.PBdr pprbasepbdr = wmlObjectFactory.createPPrBasePBdr();
    // pprbasepbdr.setBottom(null);
    // pprbasepbdr.setTop(null);
    // pprbasepbdr.setLeft(null);
    // pprbasepbdr.setRight(null);
    // pprText.setPBdr(pprbasepbdr);
    p2.setPPr(pprText);
    p.setPPr(ppr2);
    R r2 = wmlObjectFactory.createR();
    p2.getContent().add(r2);
    // Create object for rPr
    RPr rpr2 = wmlObjectFactory.createRPr();

    // // set font
    // if (font > 30)
    // font = 30;
    HpsMeasure m = new HpsMeasure();
    m.setVal(new BigInteger(font.toString()));

    rpr2.setSz(m);
    rpr2.setSzCs(m);

    r2.setRPr(rpr2);
    // Create object for lang
    CTLanguage language3 = wmlObjectFactory.createCTLanguage();
    language3.setVal("ar");
    rpr2.setLang(language3);
    rpr.setLang(language3);

    Text text = null;
    JAXBElement<org.docx4j.wml.Text> textWrapped = null;
    for (int i = 0; i < lines.size(); i++) {
        text = wmlObjectFactory.createText();
        text.setValue(lines.get(i));
        textWrapped = wmlObjectFactory.createRT(text);
        r2.getContent().add(textWrapped);
        r2.getContent().add(wmlObjectFactory.createBr());
    }
    // halamboha
    shape.setStyle("position:absolute; border: null ; " + "    width:" + boxWidth * .24 + "pt;height:"
            + boxHeight * .24 + "pt;top:" + top * .24 + "pt;left:" + left * .24 + "pt;");
    // org.docx4j.wml.STBorder.NONE;

    return p;
}

0 个答案:

没有答案