We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Deleting fields from header into a DocumentVisitor

Hi,
When doing a merge I need to compute page ranges for each merge source. To get that we insert a PAGE merge field and and ‘target’ merge field into the header, do the merge, then use a DocumentVisitor that do the stuff into visitFieldEnd() and remove the 2 fields.

This is working well but depending on the template the fields are not correctly removed. Can’t see the difference between the 2 templates.

Beside that, it would be nice to have some kind of callback that allow to count pages during merge !

Thanks
Hervé

@omniappfr

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

  • Could you please share why you need page ranges of each merge source?
  • 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 will start investigation into your issue and provide you more information. Thanks for your cooperation.

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

Hi,

WeI need page range because we are doing demateralized postal mail from the generated file and need range inside the document for each of the target. If you have a better way to get that we are open !apose-range-test.zip (26.5 KB)

this thread is related to this one : How to determine current page count during mail merge

@omniappfr

We are investigating your issue and will get back to you soon.

@omniappfr

We have checked your shared code example and noticed that you are not calling computePages method before save method. After calling this method, the page fields is deleted from the document using latest version of Aspose.Words for Java 21.8.

doc.getMailMerge().execute(src);
computePages();
doc.save(output);