Search code examples
javadocx4j

Disable expand character spaces in Docx4j


Is there a chance to disable character spaces on a line that ends with SHIFT-RETURN in Docx4j ? I am transforming html text into .docx file and i face this problem on justified aligned text. In MsWord there is special Layout Option, hope there is one in docx4j.

For Example: enter image description here

Result:

enter image description here


Solution

  • Well for those who want to know how to solve this problem, i have found the way to solve it.

    Here you go.

            WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    
            DocumentSettingsPart dsp = wordMLPackage.getMainDocumentPart().getDocumentSettingsPart();
            CTSettings settings = Context.getWmlObjectFactory().createCTSettings();
            BooleanDefaultTrue val = new BooleanDefaultTrue();
            val.setVal(true);
    
            CTCompat compat = Context.getWmlObjectFactory().createCTCompat();
            compat.setDoNotExpandShiftReturn(val);
            settings.setCompat(compat);
            dsp.setJaxbElement(settings);
            wordMLPackage.getMainDocumentPart().addTargetPart(dsp);