Controlling Numbering

Hi,

I am using Aspose Words (Java) to generate a document (PDF or Word depending on user selection). This is a fairly long document with numbered sections. At the end of the document there are ‘easy read notes’ corresponding to each section in the main body of the document. Each note is numbered to match the section it applies to.

The user is able to remove or edit the sections in the main body of the document, or remove them all together.

We have a requirement to remove the note if the user either removes or edits the section. This works fine for the case where the section is removed - I remove both the section and its notes and the numbering remains consistent. However, if I remove a note for a section that is still present, the numbering of subsequent notes no longer matches.

How would I go about removing the note but leave the ordering of subsequent notes unchanged?

Thanks in advance for any advice you can give me,

David

@davidsinclairgov,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Thanks. The attached file contains an example that tries to illustrate the question. Please read the text in the examples.docx

aspose-question.zip (114.0 KB)

@davidsinclairgov,

Thanks for sharing the detail. Please share your expected output documents for both scenarios. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.

Thanks Tahir. See attached desired output documents for the two scenarios.

Scenario 1 already produces the desired output.

Scenario 2 is the issue - in the desired output notice that the numbering in the notes skips from 1 to 3 so that the notes and the sections above match up.
expected-outputs.zip (22.9 KB)

@davidsinclairgov,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. You are using one list for all sections and one list for notes. In your case, we suggest you please use separate list for each section and note. We have attached the modified input document with this post for your kind reference. Hope this helps you. examples_modified.zip (12.8 KB)

Moreover, you can also insert endnote to your document and remove it according to your requirement.

Thanks for the advice. I don’t think either of these will work for our use case - I guess we will have to do a bit of lateral thinking.

@davidsinclairgov,

Thanks for your inquiry. Your expected output document also contains multiple lists for notes. If you do not want to modify the input document, you can modify your output document according to your requirement. Please check the following modified code snippet. Hope this helps you.

if (!initialValue.equals(editedValue)) {
    // the field is empty so remove this note.
    Section section = (Section) fieldMergingArgs.getField().getStart().getAncestor(Section.class);
    //Modified code start
    if(section.getNextSibling() != null)
    {
        Section nextSection = (Section)section.getNextSibling();
        if(nextSection.getBody().getFirstParagraph().isListItem())
        {
            ((Document)nextSection.getDocument()).updateListLabels();

            System.out.println(nextSection.getBody().getFirstParagraph().getText());

            com.aspose.words.List list =  nextSection.getDocument().getLists().addCopy(nextSection.getBody().getFirstParagraph().getListFormat().getList());
            nextSection.getBody().getFirstParagraph().getListFormat().setList(list);
            list.getListLevels().get(0).setStartAt(nextSection.getBody().getFirstParagraph().getListLabel().getLabelValue());
        }
    }
    //Modified code end
    section.remove();
}