Wiki
Clone wikiAspose Java for Docx4j / Delete-Bookmarks
Aspose.Words
Document doc = new Document("data/Aspose_Bookmark.doc"); // By name. Bookmark bookmark = doc.getRange().getBookmarks().get("AsposeBookmark"); bookmark.remove();
Docx4j
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage .load(new java.io.File("data/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("data/Docx4jBookmarkDeleted.docx"));
Download Source Code
Updated