Delete Bookmarks
Contents
[
Hide
]
Aspose.Words - Delete Bookmarks
Bookmarks can be deleted by calling bookmark.remove().
Java
Document doc = new Document(dataDir + "Aspose_Bookmark.doc");
// By name.
Bookmark bookmark = doc.getRange().getBookmarks().get("AsposeBookmark");
bookmark.remove();
docx4j - Delete Bookmarks
The following code example shows how a bookmark can be removed using docx4j.
Java
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
.load(new java.io.File(dataDir + "Docx4j_BookmarkAdd.docx"));
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
// Before..
// System.out.println(XmlUtils.marshaltoString(documentPart.getJaxbElement(), true, true));
org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document) documentPart
.getJaxbElement();
Body body = wmlDocumentEl.getBody();
fixRange(body.getContent(), "CTBookmark", "CTMarkupRange");
// After
System.out.println(XmlUtils.marshaltoString(documentPart.getJaxbElement(), true, true));
wordMLPackage.save(new java.io.File(dataDir + "Docx4jBookmarkDeleted.docx"));
Download Running Code
Download Sample Code
For more details, visit Bookmarks in Aspose.Words.