Numbering of ToC with sections

Hi,

We want to upgrade Apsose (currently we are on 17.3.0). However, we are seeing a change in behaviour that we need to resolve.

We are doing a mail merge on the attached document (model-tenancy-agreement.docx). In addition to filling in fields, we also need to selectively remove some sections depending on the input. To do this we have added Section Break’s (continuous) to the document to surround the sections we may need to remove.

In our IFieldMergingCallback, we have this code in the fieldMerging method:

// if the field is one of the fieldsToRemoveIfEmpty then remove the containing Section
if (shouldRemoveSection(fieldName, fieldValue))
{
    Section section = (Section)fieldMergingArgs.getField().getStart().getAncestor(Section.class);
    section.remove();
    return;
} 

When removing the sections, we want the table of contents to be updated accordingly, and this works ok in our current version. However, with versions 18.8 and later (have tried the most recent version), the numbering of the table of contents resets to 1 each time a new section starts, see attached output document tenancy (6).docx

Our current license expires soon and we cannot use the new one due to this issue: License update issue - #6 by alexey.noskov

Thanks for any help you can give with this,

David

Document template:
model-tenancy-agreement.docx (2.0 MB)

output document:
tenancy (6).docx (289.9 KB)

PS,

Not sure if this is relevant but here is the code we use to execute the mail merge:

template.getMailMerge().setTrimWhitespaces(true);
if (mergingCallback != null)
{
    template.getMailMerge().setFieldMergingCallback(mergingCallback);
}

try
{
    List<String> fieldnames = new ArrayList<>();
    List<Object> values = new ArrayList<>();
    fields.entrySet().stream().forEach(entry-> {
        fieldnames.add(entry.getKey());
        values.add(entry.getValue());
    });
    template.getMailMerge().execute(
            fieldnames.toArray(new String[fieldnames.size()]),
            values.toArray());

    //template.getLayoutOptions().setContinuousSectionPageNumberingRestart(ContinuousSectionRestart.FROM_NEW_PAGE_ONLY);
    template.updateFields();
    template.updatePageLayout();


    ByteArrayOutputStream out = new ByteArrayOutputStream();
    template.save(out, SaveFormat.DOCX);

@davidsinclairgov
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-25326

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thanks Alexey.

1 Like

Hi Alexey,

How can I check on progress on the above ticket?

Thanks,

David

@davidsinclairgov We have completed analyzing the issue. The issue occurs because Aspose.Words does not push the first row of a margin-relative table when it overlaps the footer. The issue is specific to 2013 compatibility mode.
The issue has been postponed and is not yet scheduled for developments. You can see the status of the issue at the bottom of this page.

Hi @alexey.noskov,

Thanks for the update.

I am not sure I understand how this causes our issue though - our template document is not in 2013 compatibility mode. We can make changes to the document if it works around this issue - can you give any hints on if this should work and if so what we might need to change?

Alternatively, is there another way we can achieve what we are trying to do (remove parts of the document depending on user input and have the table of contents update automatically)?

Thanks,

David

@davidsinclairgov The problem is actually caused by the floating table. So as a temporary workaround you can void using floating tables in your document.