Aspose.Words incorrectly removing bookmark

Hello,

I’ve attached a document. In it are two bookmarks, “OriginalBookmark” and "InsertHere"

On that document, the following code is executed (this is in ColdFusion):

<cfif docBuilder.moveToBookmark(“InsertHere”)>
<cfset docBuilder.writeln(“abcdefg”)>
<cfset docBuilder.getCurrentParagraph().remove()>

I’ve also attached the output document.

The results appear correct; however, the other bookmark, “OriginalBookmark” is missing.

It seems like the getCurrentParagraph().remove() statement not only removes the text following the newly-inserted line from writeln() – as intended – but it also goes back and removes the preceding bookmark, prior to the new line. I don’t think this is proper behavior.

Thank you.

Hi Chris,


Thanks for your inquiry.

Please note that the DocumentBuilder.MoveToBookmark method moves the cursor to a position just after the start of the bookmark with the specified name. The first two lines of your code force Bookmark to span across two Paragraphs such that the BookmarkStart node belongs to the new Paragraph containing the text “abcdefg” and BookmarkEnd node belongs to the old Paragraph containing the text “” (please see attached screenshot of DOM hierarchy). At this point cursor is inside second paragraph and when you remove it, the “InsertHere” is removed because part of this bookmark is no longer available. I think, you can simply use the code from the following article to achieve what you’re looking for.
http://www.aspose.com/docs/display/wordsjava/Bookmarks+in+Aspose.Words (see “Setting Bookmark Name and Text” example)

In case this doesn’t resolve your problem, please attach your expected Word document here for our reference. We will investigate the structure of your expected document as to how you want your final output be generated like. You can create expected document using Microsoft Word. We will provide you code to achieve the same using Aspose.Words.

Best regards,