Search code examples
javatextright-to-leftdocx4j

How do i change docx4j text direction with java?


I am writting text to a docx document using docx4j i want to change default text direction to right-to-left , this is my code:

WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();
MainDocumentPart mainDocumentPart = wordPackage.getMainDocumentPart();
mainDocumentPart.addParagraphOfText("some plain text");
File exportFile = new File("test.docx");
wordPackage.save(exportFile);

Solution

  • It is suggested to use Apache POI. Please check this page for a tutorial and use a template file for your goal as described here.