---
title: "Inserting Bookmarks Dynamically in Java"
---


You can insert bookmarks to your reports dynamically using `bookmark` tags. Syntax of a `bookmark` tag is defined as follows.

{{< highlight csharp >}}
<<bookmark [bookmark_expression]>>
bookmarked_content
<</bookmark>>
{{< /highlight >}}

Here, `bookmark_expression` defines the name of a bookmark to be inserted during runtime. This expression is mandatory and must return a non‑empty value. While building a report, `bookmark_expression` is evaluated and its result is used to construct a bookmark start and end that replace corresponding opening and closing `bookmark` tags respectively.

**Note** – A `bookmark` tag cannot be used within a chart.

------ 

## FAQ

1. **Q:** How can I generate the bookmark name at runtime?  
   **A:** Use any valid expression that returns a string, such as a field from your data source or a concatenation of values. For example: `<<bookmark [\"Section_\" + data[\"Id\"]]>>`.

2. **Q:** Can a `bookmark` tag be placed inside a table cell?  
   **A:** Yes, the `bookmark` tag works inside tables, paragraphs, and most other document elements. The only restriction is that it cannot be used inside a chart.

3. **Q:** How do I reference a dynamically created bookmark later in the document?  
   **A:** After the report is generated, you can retrieve the bookmark by its runtime name using `Document.getBookmarks().get(\"BookmarkName\")`. Ensure the name you generated is stored or predictable so you can access it later.

4. **Q:** What happens if the bookmark expression evaluates to an empty string?  
   **A:** The engine will throw an error because a bookmark name is required and cannot be empty. Always validate that the expression returns a non‑empty value before the tag is processed.

5. **Q:** Is it possible to create multiple bookmarks with the same name?  
   **A:** No. Bookmark names must be unique within a document. If you attempt to insert a duplicate name, Aspose.Words will replace the existing bookmark, potentially causing loss of the original bookmark’s range. Use distinct names for each bookmark.