JAVA with POI XWPF

how can I set paragraph property "Keep with next" in POI XWPF? I tried to look for an example, but I did not find. I would like to have a Title paragraph together with your "body" paragraph. In Word, you can specify a property in Paragraph Dialog called "Keep with next". How can I do it in POI XWPF?

Upvotes: 0

Views: 528

Answers (1)

jmarkmurphy
jmarkmurphy

Reputation: 11493

You can set a paragraph to a style that includes Keep with next. For example the Heading# styles default to Keep with next.

Otherwise you will have to use the CT classes like this

CTP ctP = xwpfParagraph.getCTP();
CTPPr ctPPr = ctP.isSetPPr() ? ctP.getPPr() : ctP.addNewPPr();
CTOnOff keepNext = CTOnOff.Factory.newInstance();
keepNext.setVal(STOnOff.ON);
ctPPr.setKeepNext(keepNext);

Upvotes: 1

Related Questions