# Customize bookmark
This section mainly introduces the customization methods of the bookmark component. Since the bookmark component is developed based on the tree component, please first understand the usage of the tree component and the related API documentation (opens new window).
# Bookmark Component Structure
This section introduces the template structure of bookmark-related components, involving the sidebar panel component, bookmark context menu component, and bookmark tree node component.
# Bookmark sidebar panel
In the built-in layout templates, <bookmark-v2:sidebar-panel></bookmark-v2:sidebar-panel>
refers to the left sidebar bookmark panel, which is actually equivalent to the following complex template:
<sidebar-panel
name="sidebar-bookmark-v2"
class="fv__ui-sidebar-bookmark-v2"
@tooltip
tooltip-placement="right"
tooltip-title="sidebar.bookmark.tooltip"
title="sidebar.bookmark.title"
icon-class="fv__icon-sidebar-bookmark"
@lazy-content="active"
>
<bookmark-v2:bookmark-tree></bookmark-v2:bookmark-tree>
</sidebar-panel>
In the application, the complex template can replace the built-in simplified template and modify its attributes:
# Bookmark context menu
In the built-in layout template, <bookmark-v2:bookmark-contextmenu @lazy></bookmark-v2:bookmark-contextmenu>
refers to the bookmark context menu. It is equivalent to the following template:
<contextmenu name="fv--bookmark-contextmenu-v2">
<bookmark-v2:add-bookmark name="fv--bookmark-contextmenu-item-add"></bookmark-v2:add-bookmark>
<contextmenu-separator @bookmark-v2:hide-if-no-bookmark></contextmenu-separator>
<bookmark-v2:goto-bookmark @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-goto"></bookmark-v2:goto-bookmark>
<contextmenu-separator @bookmark-v2:hide-if-no-bookmark></contextmenu-separator>
<bookmark-v2:cut-bookmark @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-cut"></bookmark-v2:cut-bookmark>
<bookmark-v2:paste-under-selected-bookmark @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-paste-under"></bookmark-v2:paste-under-selected-bookmark>
<bookmark-v2:paste-after-selected-bookmark @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-paste-after"></bookmark-v2:paste-after-selected-bookmark>
<bookmark-v2:delete-bookmark @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-delete"></bookmark-v2:delete-bookmark>
<bookmark-v2:set-destination @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-set-destination"></bookmark-v2:set-destination>
<bookmark-v2:rename-bookmark @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-rename"></bookmark-v2:rename-bookmark>
</contextmenu>
In the template, for the menu items, a @bookmark-v2:hide-if-no-bookmark
directive is provided. The function of this directive is: when there are no bookmarks in the document, right-click on the bookmark panel, we need to hide some menu items, leaving only the <bookmark-v2:add-bookmark>
component.
Based on this template, we just need to define a context menu named fv--bookmark-contextmenu-v2
, replacing the built-in bookmark context menu, to achieve the effect of overriding the built-in bookmark context menu. Below is an example:
Of course, apart from replacing the whole built-in bookmark context menu, you can also delete or add menu items individually:
# Bookmark context menu items
- Add bookmark menu item:
- Simplified template:
<bookmark-v2:add-bookmark name="fv--bookmark-contextmenu-item-add"></bookmark-v2:add-bookmark>
- Complete template:
<contextmenu-item @controller="AddBookmarkController">contextmenu.bookmark.add</contextmenu-item>
- Simplified template:
- Navigation function menu item:
- Simplified template:
<bookmark-v2:goto-bookmark @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-goto"></bookmark-v2:goto-bookmark>
- Complete template:
<contextmenu-item @controller="GotoBookmarkController" @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-goto">contextmenu.bookmark.goTo</contextmenu-item>
- Simplified template:
- Cut function menu item:
- Simplified template:
<bookmark-v2:cut-bookmark @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-cut"></bookmark-v2:cut-bookmark>
- Complete template:
<contextmenu-item @controller="CutBookmarkController" @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-cut">contextmenu.bookmark.cut</contextmenu-item>
- Simplified template:
- Paste bookmark under the selected bookmark function menu item:
- Simplified template:
<bookmark-v2:paste-under-selected-bookmark @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-paste-under"></bookmark-v2:paste-under-selected-bookmark>
- Complete template:
<contextmenu-item @controller="PasteUnderSelectedBookmarkController as ctrl" @show="ctrl.pasteAvailable" @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-paste-under">contextmenu.bookmark.pasteUnder</contextmenu-item>
- Simplified template:
- Paste bookmark after the selected bookmark function menu item:
- Simplified template:
<bookmark-v2:paste-after-selected-bookmark @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-paste-after"></bookmark-v2:paste-after-selected-bookmark>
- Complete template:
<contextmenu-item @controller="PasteAfterSelectedBookmarkController as ctrl" @show="ctrl.pasteAvailable" @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-paste-after">contextmenu.bookmark.pasteAfter</contextmenu-item>
- Simplified template:
- Delete bookmark function menu item:
- Simplified template:
<bookmark-v2:delete-bookmark @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-delete"></bookmark-v2:delete-bookmark>
- Complete template:
<contextmenu-item @controller="DeleteBookmarkController" @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-delete">contextmenu.bookmark.delete</contextmenu-item>
- Simplified template:
- Set bookmark target location menu item:
- Simplified template:
<bookmark-v2:set-destination @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-set-destination"></bookmark-v2:set-destination>
- Complete template:
<contextmenu-item @controller="SetDestinationBookmarkController" @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-set-destination">contextmenu.bookmark.destination</contextmenu-item>
- Simplified template:
- Rename bookmark menu item:
- Simplified template:
<bookmark-v2:rename-bookmark @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-rename"></bookmark-v2:rename-bookmark>
- Complete template:
<contextmenu-item @controller="RenameBookmarkController" @bookmark-v2:hide-if-no-bookmark name="fv--bookmark-contextmenu-item-rename">contextmenu.bookmark.rename</contextmenu-item>
- Simplified template:
These are the built-in bookmark context menu items supported by Foxit PDF SDK for Web. The application layer can reuse the @controller
implementation of these menu items and replace the built-in menu items to create custom menu item functions. Below is an example:
# Bookmark tree node
The bookmark tree node, also known as TreeNodeComponent (opens new window), synchronizes with the bookmark data of the PDF document, and is created or destroyed following the creation or deletion of the bookmark data. Therefore, to customize the bookmark tree node, it needs to be done through events. The TreeComponent (opens new window) component has made these two events available:
create-tree-node
event is triggered when a tree node is created. It can be used to modify the appearance of the tree node and register events on the tree node, etc.destroy-tree-node
event is triggered when a tree node is destroyed. It can be used to release some data to avoid memory leaks.
Below is an example that demonstrates how to replace the text content of a tree node with a link:
# Bookmark Service API
Based on the differences between the PDFViewCtrl layer and the UIExtension layer, we have divided the bookmark API into two parts and provided two Service instances:
BookmarkDataService (opens new window): Bookmark data service at the PDFViewCtrl layer. When your application is developed based on PDFViewCtrl, you can only use the API provided by this service for extension.
BookmarkUIService (opens new window): The UIExtension layer APIs encapsulated based on
BookmarkDataService
, which encapsulates some APIs ofBookmarkDataService
, are used to support the synchronization of view and data at the UI layer and theundo-redo
functionality.The UIExtension layer can also use
BookmarkDataService
, but apart from the APIs encapsulated inBookmarkUIService
. For specific details, please refer to the API Reference (opens new window).
# Example 1
A basic demonstration of retrieving and printing first-level bookmarks via BookmarkDataService
:
# Example 2
A basic demonstration of creating and deleting bookmarks via BookmarkUIService
: