Search in sources :

Example 11 with P

use of org.docx4j.wml.P in project Java-Tutorial by gpcodervn.

the class NumberingTest method testUnorderedCssOnLiToIndent.

// ===============================================================================
// indentation tests
// TODO: broken in 3.3.6; revisit this
@Ignore
public void testUnorderedCssOnLiToIndent() throws Docx4JException {
    this.addNumberingPart(wordMLPackage.getMainDocumentPart());
    this.addStylesPart(wordMLPackage.getMainDocumentPart());
    String xhtml = "<div>" + "<ul>" + // TODO this is currently ignored?
    "<li style=\"margin-left: 1in;\">List item one</li>" + "</ul>" + "</div>";
    List<Object> results = convert(xhtml, FormattingOption.IGNORE_CLASS);
    wordMLPackage.getMainDocumentPart().getContent().addAll(results);
    System.out.println(XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true));
    // System.out.println(XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getNumberingDefinitionsPart().getJaxbElement(), true, true));
    P p = (P) results.get(0);
    // Should be numbered, but not using our predefined list
    assertTrue(p.getPPr().getNumPr() != null);
    assertTrue(p.getPPr().getNumPr().getNumId() != null);
    assertTrue(p.getPPr().getNumPr().getNumId().getVal().intValue() != PREDEFINED_OL_NUMID);
    // default of 600 + 1440 + hanging hack (360)
    // TODO this shouldn't be necessary
    wordMLPackage.getMainDocumentPart().getNumberingDefinitionsPart().initialiseMaps();
    Ind ind = wordMLPackage.getMainDocumentPart().getNumberingDefinitionsPart().getInd(p.getPPr().getNumPr());
    System.out.println(XmlUtils.marshaltoString(ind));
    assertTrue(ind.getLeft().intValue() == 2400);
}
Also used : P(org.docx4j.wml.P) Ind(org.docx4j.wml.PPrBase.Ind) Ignore(org.junit.Ignore)

Example 12 with P

use of org.docx4j.wml.P in project Java-Tutorial by gpcodervn.

the class NumberingTest method testNestedNoClass.

// ===============================================================================
// nested list tests
/**
 * For a nested list, we should get ilvl right; there should no pPr ind
 */
@Test
public void testNestedNoClass() throws Docx4JException {
    this.addNumberingPart(wordMLPackage.getMainDocumentPart());
    this.addStylesPart(wordMLPackage.getMainDocumentPart());
    String xhtml = "<div>" + "<ul>" + "<li>List item two with subitems:" + "<ul>" + "<li>Subitem 1</li>" + "</ul>" + "</li>" + "</ul>" + "</div>";
    List<Object> results = convert(xhtml, FormattingOption.IGNORE_CLASS);
    wordMLPackage.getMainDocumentPart().getContent().addAll(results);
    System.out.println(XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true));
    // System.out.println(XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getNumberingDefinitionsPart().getJaxbElement(), true, true));
    P p = (P) results.get(1);
    // Should be numbered, but not using our predefined list
    assertTrue(p.getPPr().getNumPr() != null);
    assertTrue(p.getPPr().getNumPr().getNumId() != null);
    assertTrue(p.getPPr().getNumPr().getNumId().getVal().intValue() != PREDEFINED_OL_NUMID);
    assertTrue(p.getPPr().getNumPr().getIlvl() != null);
    // nested
    assertTrue(p.getPPr().getNumPr().getIlvl().getVal().intValue() == 1);
    // Indent should not be present in pPr
    assertTrue(p.getPPr().getInd() == null);
}
Also used : P(org.docx4j.wml.P) Test(org.junit.Test)

Example 13 with P

use of org.docx4j.wml.P in project Java-Tutorial by gpcodervn.

the class Docx4jUtils method newImage.

public P newImage(WordprocessingMLPackage wordMLPackage, byte[] bytes, String filenameHint, String altText, int id1, int id2, long cx) throws Exception {
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
    Inline inline = imagePart.createImageInline(filenameHint, altText, id1, id2, cx, false);
    // Now add the inline in w:p/w:r/w:drawing
    ObjectFactory factory = Context.getWmlObjectFactory();
    P p = factory.createP();
    R run = factory.createR();
    p.getContent().add(run);
    Drawing drawing = factory.createDrawing();
    run.getContent().add(drawing);
    drawing.getAnchorOrInline().add(inline);
    return p;
}
Also used : P(org.docx4j.wml.P) Drawing(org.docx4j.wml.Drawing) R(org.docx4j.wml.R) ObjectFactory(org.docx4j.wml.ObjectFactory) Inline(org.docx4j.dml.wordprocessingDrawing.Inline) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)

Example 14 with P

use of org.docx4j.wml.P in project Java-Tutorial by gpcodervn.

the class Write_Image method main.

public static void main(String[] args) throws Exception {
    WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();
    MainDocumentPart mainDocumentPart = wordPackage.getMainDocumentPart();
    mainDocumentPart.addStyledParagraphOfText("Title", "Hello World!");
    mainDocumentPart.addParagraphOfText("Welcome To Baeldung");
    File image = new File("resources/image.png");
    byte[] fileContent = Files.readAllBytes(image.toPath());
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordPackage, fileContent);
    Inline inline = imagePart.createImageInline("Baeldung Image (filename hint)", "Alt Text", 1, 2, false);
    P Imageparagraph = addImageToParagraph(inline);
    mainDocumentPart.getContent().add(Imageparagraph);
    File exportFile = new File("output/welcome3.docx");
    wordPackage.save(exportFile);
    System.out.println("Done!");
}
Also used : P(org.docx4j.wml.P) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) Inline(org.docx4j.dml.wordprocessingDrawing.Inline) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage) File(java.io.File)

Example 15 with P

use of org.docx4j.wml.P in project docx4j-template by vindell.

the class Docx4J_例子2 method getTextHdr.

public Hdr getTextHdr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, boolean isUnderLine, String underLineSz, JcEnumeration jcEnumeration) throws Exception {
    Hdr hdr = factory.createHdr();
    P headP = factory.createP();
    Text text = factory.createText();
    text.setValue(content);
    R run = factory.createR();
    run.getContent().add(text);
    headP.getContent().add(run);
    PPr pPr = headP.getPPr();
    if (pPr == null) {
        pPr = factory.createPPr();
    }
    Jc jc = pPr.getJc();
    if (jc == null) {
        jc = new Jc();
    }
    jc.setVal(jcEnumeration);
    pPr.setJc(jc);
    if (isUnderLine) {
        PBdr pBdr = pPr.getPBdr();
        if (pBdr == null) {
            pBdr = factory.createPPrBasePBdr();
        }
        CTBorder value = new CTBorder();
        value.setVal(STBorder.SINGLE);
        value.setColor("000000");
        value.setSpace(new BigInteger("0"));
        value.setSz(new BigInteger(underLineSz));
        pBdr.setBetween(value);
        pPr.setPBdr(pBdr);
        headP.setPPr(pPr);
    }
    setParagraphSpacing(factory, headP, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO);
    hdr.getContent().add(headP);
    if (isUnderLine) {
        hdr.getContent().add(createHeaderBlankP(wordprocessingMLPackage, factory, underLineSz, jcEnumeration));
    }
    return hdr;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) PBdr(org.docx4j.wml.PPrBase.PBdr) CTBorder(org.docx4j.wml.CTBorder) Hdr(org.docx4j.wml.Hdr) STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) BigInteger(java.math.BigInteger) Text(org.docx4j.wml.Text)

Aggregations

P (org.docx4j.wml.P)101 R (org.docx4j.wml.R)58 Text (org.docx4j.wml.Text)32 Test (org.junit.Test)23 PPr (org.docx4j.wml.PPr)22 RPr (org.docx4j.wml.RPr)21 ObjectFactory (org.docx4j.wml.ObjectFactory)18 Jc (org.docx4j.wml.Jc)16 BigInteger (java.math.BigInteger)14 CTVerticalJc (org.docx4j.wml.CTVerticalJc)14 Drawing (org.docx4j.wml.Drawing)14 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)13 STVerticalJc (org.docx4j.wml.STVerticalJc)11 Tc (org.docx4j.wml.Tc)11 File (java.io.File)10 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)10 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)10 Tbl (org.docx4j.wml.Tbl)10 Tr (org.docx4j.wml.Tr)10 Br (org.docx4j.wml.Br)9