Page 1 of 1

Bookmark selection removal

PostPosted: Fri Apr 26, 2013 5:09 pm
by Chethan
Hi,

Currently I'm using the Docx4j API to modify the word template and has one query regarding bookmark contents.
I've huge word template (414 pages) with many bookmarks in it. I can remove all the bookmarks using BookmarksDeleter sample.
Now I have to remove corresponding selection of bookmark. Modification/String manipulation of document.xml was not feasible as bookmarks span across paragraphs.

If using ACTIVE X, it is achieved via below code:-
myDocument.Bookmarks(deleteBookMarkName).Select();
myDocument.Application.Selection.Delete();

I was looking for similar kind of selection and deletion of bookmark content was possible in docx4j.

Thanks,
Chethan

Re: Bookmark selection removal

PostPosted: Tue Apr 30, 2013 10:13 am
by jason
Hi Chethan

There is no high level function in docx4j to remove the contents of a bookmark.

However, everything you need is there at a low level to implement this functionality yourself.

The slight challenge you face is that a bookmark could start, for example, in a paragraph in a table cell, and finish in some paragraph further down the document outside the table.

It ought to be enough to find the bookmark start, then delete content (using a traversal approach) until you reach the bookmark end.

hope this helps .. Jason