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