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);