Deleting a bookmark
Posted: Fri Jun 19, 2015 11:53 pm
Strange thing. I'm trying to delete a "_GoBack" bookmark in a docx file, because it's ruining VariablePrepare (interesting, but different topic). I have a very simple template, and there is only one bookmark, which is:
It appears anytime i make a change in the template, in the place of the last change.
This code:
gives me "_GoBack", so i'm sure that the bookmark is found correctly. But strangely if i do this:
the bookmark doesn't get deleted. To check, this code:
returns
Should i use some other approach to delete a bookmark in docx4j?
This question is also posted at stackoverflow: http://stackoverflow.com/questions/30937551/how-can-i-delete-a-bookmark-using-docx4j
- Code: Select all
<w:bookmarkStart w:id="0" w:name="_GoBack"/>
<w:bookmarkEnd w:id="0"/>
It appears anytime i make a change in the template, in the place of the last change.
This code:
- Code: Select all
MainDocumentPart main = docx.getMainDocumentPart();
List<Object> bmList = getAllElementFromObject(main, CTBookmark.class);
CTBookmark bm = (CTBookmark) bmList.get(0);
System.out.println(bm.getName());
gives me "_GoBack", so i'm sure that the bookmark is found correctly. But strangely if i do this:
- Code: Select all
getAllElementFromObject(main, CTBookmark.class).remove(0);
the bookmark doesn't get deleted. To check, this code:
- Code: Select all
System.out.println(getAllElementFromObject(main, CTBookmark.class).size());
getAllElementFromObject(main, CTBookmark.class).remove(0);
System.out.println(getAllElementFromObject(main, CTBookmark.class).size());
returns
- Code: Select all
1
1
Should i use some other approach to delete a bookmark in docx4j?
This question is also posted at stackoverflow: http://stackoverflow.com/questions/30937551/how-can-i-delete-a-bookmark-using-docx4j