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

Free Support Forum - aspose.com

Multiple References to the same bookmark name

I have just started evaluating Aspose.Words for Java and was particularly pleased how easy it was to open a document, populate bookmarks with values and write the modified document as DOCX and PDF.

However, we have a number of templates where the the same bookmark name appears several times in the document. In this case I am able to set the first occurence of this bookmark with text, but subsequent references are not populated.

There is nothing obvious in the various classes Bookmark, BookmarkStart and BookmarkEnd.

Also the BookmarkStart method isComposite() returns false for the first occurence, although I suspect this has nothing to do with susbsequent bookmark references.

I have found some reference to ChildBookmarks on your web site, but this appears to be associated with .NET

I would be grateful if someone could offer some guidance on this.


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. MS Word documents cannot contain few bookmarks with the same name. You cannot insert bookmarks with the same name using MS Word. Could you please attach your sample document here for testing?

Also, maybe in your case it is better to use mergefields and Mail Merge approach to fill the document with data:


Best regards.


Many thanks for your reply. I have attached the document template, which you will note contains multiple references to the bookmark among other references.


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Your document contains only one bookmark named “Developer_Name”. See the attached screenshot.

< Developer Name> is not a bookmark, but it is just simple text. As I already mentioned, Mail Merge approach should fulfill your requirements.

Also, if you would like to use text placeholders, like “< Developer Name>”, you can use Range.Replace method:


Best regards.


Many thanks for your further feedback. A colleague has found with the .NET automation that the entries in document.xml extracted from the template I provided that have the tag structure:

<w:fldSimple w:instr="REF Developer_Name \h \* MERGEFORMAT">

can be found with document.Fields

We would particularly like to adopt a pure Java solution such as Aspose, as your web site suggests this to be a more reliable solution than using .NET automation.

Were you suggesting that I should modify the template to use the Maile Merge approach?

We have an existing system which processes several thousand documents a day from around 100 different templates which are currently populated using VB macros. These templates are maintained by our customers and so we have no influence over them apart from offering general guidlines.

I would be grateful for your further assistance. I am also keen to know how to replace an image or a table into a bookmark place-holder.



<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Please see the following ink to learn how to insert merge field into a document:


In MS Word 2007, you can find the same in Insert tab / Quick Parts / Insert Field.

Please see also the following link to learn how to execute mail merge:


You can use DocumentBuilder to insert table or images at bookmark. You should just use DocumentBuidler.MoveToBookmark method to move DocuemntBuilder cursor to the bookmarks, and then use DocumentBuilder.InsertImage method to insert an image or DocumentBuilder.StartTable/InsertCell/EndRow/EndTable methods to build a table:



Hope this helps.

Best regards.