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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations