public static void main(String[] args) throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
// Add numbering part
NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
ndp.setJaxbElement( (Numbering) XmlUtils.unmarshalString(initialNumbering) );
// Add some document content
wordMLPackage.getMainDocumentPart().addParagraphOfText("Example of restarting numbering");
P p = createNumberedParagraph(1, 0, "text on top level" );
wordMLPackage.getMainDocumentPart().addObject(p);
wordMLPackage.getMainDocumentPart().addObject(
createNumberedParagraph(1, 0, "more text on top level" ));
wordMLPackage.getMainDocumentPart().addObject(
createNumberedParagraph(1, 1, "text on level 1" ));
// Ok, lets restart numbering
long newNumId = ndp.restart(1, 0, 1);
wordMLPackage.getMainDocumentPart().addObject(
createNumberedParagraph(newNumId, 0, "text on top level - restarted" ));
// After first using newNumId, it doesn't matter whether