I have a paragraph of text which I would like to appear in the center of the document. How can I do this in docx4j? I am currently using:
    PPr paragraphProperties = factory.createPPr();
    //creating the alignment
    TextAlignment align = new TextAlignment();
    align.setVal("center");
    paragraphProperties.setTextAlignment(align);
    //centering the paragraph
    paragraph.setPPr(paragraphProperties);
but it isn't working.
You're almost there. Rather than setting this with a TextAlignment object, use a Jc instance (justification) instead:
PPr paragraphProperties = factory.createPPr();
Jc justification = factory.createJc();
justification.setVal(JcEnumeration.CENTER);
paragraphProperties.setJc(justification);
A simple way of figuring this stuff out:
document.xml file thereinIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With