com.aspose.words

Class Bookmark

  • java.lang.Object
    • com.aspose.words.Bookmark
public class Bookmark 
extends java.lang.Object

Represents a single bookmark.

Bookmark is a "facade" object that encapsulates two nodes BookmarkStart and BookmarkEnd in a document tree and allows to work with a bookmark as a single object.

Example:

Shows how to get or set bookmark name and text.
Document doc = new Document(getMyDir() + "Bookmark.doc");

// Use the indexer of the Bookmarks collection to obtain the desired bookmark.
Bookmark bookmark = doc.getRange().getBookmarks().get("MyBookmark");

// Get the name and text of the bookmark.
String name = bookmark.getName();
String text = bookmark.getText();

// Set the name and text of the bookmark.
bookmark.setName("RenamedBookmark");
bookmark.setText("This is a new bookmarked text.");

Property Getters/Setters Summary
BookmarkEndgetBookmarkEnd()
Gets the node that represents the end of the bookmark.
BookmarkStartgetBookmarkStart()
Gets the node that represents the start of the bookmark.
java.lang.StringgetName()
void
setName(java.lang.Stringvalue)
           Gets or sets the name of the bookmark.
java.lang.StringgetText()
void
setText(java.lang.Stringvalue)
           Gets or sets the text enclosed in the bookmark.
 
Method Summary
voidremove()
Removes the bookmark from the document. Does not remove text inside the bookmark.
 

    • Property Getters/Setters Detail

      • getBookmarkEnd

        public BookmarkEnd getBookmarkEnd()
        
        Gets the node that represents the end of the bookmark.
      • getBookmarkStart

        public BookmarkStart getBookmarkStart()
        
        Gets the node that represents the start of the bookmark.
      • getName/setName

        public java.lang.String getName() / public void setName(java.lang.String value)
        
        Gets or sets the name of the bookmark. Note that if you change the name of a bookmark to a name that already exists in the document, no error will be given and only the first bookmark will be stored when you save the document.

        Example:

        Shows how to replace elements in bookmark name
        Document doc = new Document(getMyDir() + "Bookmarks.Replace.docx");
        
        
        //MS Word document does not support bookmark names with whitespaces by default. 
        //If you have document which contains bookmark names with underscores, you can simply replace them to whitespaces.
        for (Bookmark bookmark : doc.getRange().getBookmarks())
        {
            bookmark.setName(bookmark.getName().replace("_", " "));
        }

        Example:

        Shows how to get or set bookmark name and text.
        Document doc = new Document(getMyDir() + "Bookmark.doc");
        
        // Use the indexer of the Bookmarks collection to obtain the desired bookmark.
        Bookmark bookmark = doc.getRange().getBookmarks().get("MyBookmark");
        
        // Get the name and text of the bookmark.
        String name = bookmark.getName();
        String text = bookmark.getText();
        
        // Set the name and text of the bookmark.
        bookmark.setName("RenamedBookmark");
        bookmark.setText("This is a new bookmarked text.");
      • getText/setText

        public java.lang.String getText() / public void setText(java.lang.String value)
        
        Gets or sets the text enclosed in the bookmark.

        Example:

        Shows how to get or set bookmark name and text.
        Document doc = new Document(getMyDir() + "Bookmark.doc");
        
        // Use the indexer of the Bookmarks collection to obtain the desired bookmark.
        Bookmark bookmark = doc.getRange().getBookmarks().get("MyBookmark");
        
        // Get the name and text of the bookmark.
        String name = bookmark.getName();
        String text = bookmark.getText();
        
        // Set the name and text of the bookmark.
        bookmark.setName("RenamedBookmark");
        bookmark.setText("This is a new bookmarked text.");
    • Method Detail

      • remove

        public void remove()
                   throws java.lang.Exception
        Removes the bookmark from the document. Does not remove text inside the bookmark.

        Example:

        Shows how to remove a particular bookmark from a document.
        Document doc = new Document(getMyDir() + "Bookmark.doc");
        
        // Use the indexer of the Bookmarks collection to obtain the desired bookmark.
        Bookmark bookmark = doc.getRange().getBookmarks().get("MyBookmark");
        
        // Remove the bookmark. The bookmarked text is not deleted.
        bookmark.remove();