Search in sources :

Example 61 with P

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

the class NumberingTest method testUnorderedWithStyleOnlyAndAbsent.

@Test
public void testUnorderedWithStyleOnlyAndAbsent() throws Docx4JException {
    this.addNumberingPart(wordMLPackage.getMainDocumentPart());
    this.addStylesPart(wordMLPackage.getMainDocumentPart());
    String xhtml = "<div>" + "<ul class=\"My_MISSING_ListStyle\">" + "<li>List item one</li>" + "</ul>" + "</div>";
    List<Object> results = convert(xhtml, FormattingOption.CLASS_TO_STYLE_ONLY);
    P p = (P) results.get(0);
    // Can't number
    assertTrue(p.getPPr().getNumPr() == null);
    // CLASS_TO_STYLE_ONLY, so Indent should not be present in pPr
    assertTrue(p.getPPr().getInd() == null);
}
Also used : P(org.docx4j.wml.P) Test(org.junit.Test)

Example 62 with P

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

the class NumberingTest method testUnorderedCssOnUlToIndent.

/**
 * We go to some effort to honour an 'inherited' value.
 */
@Test
public void testUnorderedCssOnUlToIndent() throws Docx4JException {
    this.addNumberingPart(wordMLPackage.getMainDocumentPart());
    this.addStylesPart(wordMLPackage.getMainDocumentPart());
    String xhtml = "<div>" + "<ul style=\"margin-left: 0.5in;\">" + "<li>List item one</li>" + "</ul>" + "</div>";
    // 40px default = 600
    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);
    // 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() == 1680);
}
Also used : P(org.docx4j.wml.P) Ind(org.docx4j.wml.PPrBase.Ind) Test(org.junit.Test)

Example 63 with P

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

the class NumberingTest method testNestedWithClass.

/**
 * For a nested list, we should get ilvl right; there should no pPr ind
 */
@Test
public void testNestedWithClass() throws Docx4JException {
    this.addNumberingPart(wordMLPackage.getMainDocumentPart());
    this.addStylesPart(wordMLPackage.getMainDocumentPart());
    String xhtml = "<div>" + "<ul>" + "<li>List item two with subitems:" + "<ul class=\"MyListStyle\">" + "<li>Subitem 1</li>" + "</ul>" + "</li>" + "</ul>" + "</div>";
    List<Object> results = convert(xhtml, FormattingOption.CLASS_PLUS_OTHER);
    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, 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 be present in pPr
    assertTrue(p.getPPr().getInd() == null);
}
Also used : P(org.docx4j.wml.P) Test(org.junit.Test)

Example 64 with P

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

the class NumberingTest method testUnorderedIgnoreClass.

@Test
public void testUnorderedIgnoreClass() throws Docx4JException {
    this.addNumberingPart(wordMLPackage.getMainDocumentPart());
    this.addStylesPart(wordMLPackage.getMainDocumentPart());
    String xhtml = "<div>" + "<ul class=\"MyListStyle\">" + "<li>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);
}
Also used : P(org.docx4j.wml.P) Test(org.junit.Test)

Example 65 with P

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

the class Docx4jUtils method createTableWithContent.

/**
 * Our createTableWithContent method follows (we use dxa values). There are 4
 * rows, some cells with vertical merge, and some with horizontal merge.
 */
private Tbl createTableWithContent() {
    Tbl table = factory.createTbl();
    // for TEST: this adds borders to all cells
    TblPr tblPr = new TblPr();
    TblStyle tblStyle = new TblStyle();
    tblStyle.setVal("TableGrid");
    tblPr.setTblStyle(tblStyle);
    table.setTblPr(tblPr);
    Tr tableRow = factory.createTr();
    // a default table cell style
    DocxStyle defStyle = new DocxStyle();
    defStyle.setBold(false);
    defStyle.setItalic(false);
    defStyle.setUnderline(false);
    defStyle.setHorizAlignment(JcEnumeration.CENTER);
    // a specific table cell style
    DocxStyle style = new DocxStyle();
    style.setBold(true);
    style.setItalic(true);
    style.setUnderline(true);
    style.setFontSize("40");
    style.setFontColor("FF0000");
    style.setFontFamily("Book Antiqua");
    style.setTop(300);
    style.setBackground("CCFFCC");
    style.setVerticalAlignment(STVerticalJc.CENTER);
    style.setHorizAlignment(JcEnumeration.CENTER);
    style.setBorderTop(true);
    style.setBorderBottom(true);
    style.setNoWrap(true);
    addTableCell(tableRow, "Field 1", 3500, style, 1, null);
    // start vertical merge for Filed 2 and Field 3 on 3 rows
    addTableCell(tableRow, "Field 2", 3500, defStyle, 1, "restart");
    addTableCell(tableRow, "Field 3", 1500, defStyle, 1, "restart");
    table.getContent().add(tableRow);
    tableRow = factory.createTr();
    addTableCell(tableRow, "Text", 3500, defStyle, 1, null);
    addTableCell(tableRow, "", 3500, defStyle, 1, "");
    addTableCell(tableRow, "", 1500, defStyle, 1, "");
    table.getContent().add(tableRow);
    tableRow = factory.createTr();
    addTableCell(tableRow, "Interval", 3500, defStyle, 1, null);
    addTableCell(tableRow, "", 3500, defStyle, 1, "close");
    addTableCell(tableRow, "", 1500, defStyle, 1, "close");
    table.getContent().add(tableRow);
    // add an image horizontally merged on 3 cells
    String filenameHint = null;
    String altText = null;
    int id1 = 0;
    int id2 = 1;
    byte[] bytes;
    try {
        bytes = getImageBytes(new File("/resources/image.png"));
        P pImage = newImage(wordMLPackage, bytes, filenameHint, altText, id1, id2, 8500);
        tableRow = factory.createTr();
        addTableCell(tableRow, pImage, 8500, defStyle, 3, null);
        table.getContent().add(tableRow);
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return table;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) TblStyle(org.docx4j.wml.CTTblPrBase.TblStyle) IOException(java.io.IOException) TblPr(org.docx4j.wml.TblPr) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException) P(org.docx4j.wml.P) File(java.io.File) Tr(org.docx4j.wml.Tr) Tbl(org.docx4j.wml.Tbl)

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