Main Toolbar
The main toolbar in ComPDF is designed to be flexible and highly configurable. This guide demonstrates how to define main toolbar options and add completely custom menu items.
This section covers:
- Configuring existing toolbar button items
- Adding more menu options
- Customizing menu options
Default Toolbar
The default toolbar contains the following tools.
| Android | iOS |
|---|---|
![]() | ![]() |
Customizing the Toolbar Buttons
You can customize the main toolbar buttons when displaying a PDF using the toolbarLeftItems and toolbarRightItems properties. The following example configures Android and iOS separately because each platform has different default toolbar positions and interactions:
<CPDFReaderView
ref={pdfReaderRef}
document={samplePDF}
onIOSClickBackPressed={handleBack}
configuration={ComPDFKit.getDefaultConfig({
toolbarConfig: {
toolbarLeftItems: Platform.OS === "android"
? ['back', 'thumbnail']
: ['back'],
toolbarRightItems: Platform.OS === "android"
? ['search', 'bota']
: ['search', 'thumbnail', 'bota', 'menu']
}
})}
/>2
3
4
5
6
7
8
9
10
11
12
13
14
15
The customized toolbar will look like what’s shown below.
| Android | iOS |
|---|---|
![]() | ![]() |
Available Toolbar Option Types
| Toolbar Button Item | Description |
|---|---|
| back | Displays a close button. |
| thumbnail | Displays a thumbnail button. |
| search | Displays a search button. |
| bota | Displays the outline, bookmarks, and annotations list button. |
| menu | Displays a menu button. |
| viewSettings | Opens the settings view to configure scroll direction, display mode, theme color, and other related settings. |
| documentEditor | Opens the document thumbnail list, allowing users to delete, rotate, or add pages in the view. |
| documentInfo | Opens the document info view to display basic document details and permissions. |
| watermark | Opens the watermark editing view to add text and image watermarks and save them as a new document. |
| security | Opens the security settings view to set document open password and permissions password. |
| flattened | Flattens annotations in the document; annotations will no longer be editable. |
| save | Saves the PDF document. |
| share | Opens the system share feature. |
| openDocument | Opens the system file picker to open a new PDF document. |
| snip | Starts the screenshot selection tool. |
| custom | Custom menu option. |
More Menu
By configuring CPDFToolbarAction.menu in the main toolbar, you can display additional menu options. Clicking on it will display a dialog with more functionality choices. Configure the more menu using availableMenus, following the same configuration method as toolbar buttons.
Here is a configuration example:
<CPDFReaderView
ref={pdfReaderRef}
document={samplePDF}
onIOSClickBackPressed={handleBack}
configuration={ComPDFKit.getDefaultConfig({
toolbarConfig: {
availableMenus: [
CPDFToolbarAction.VIEW_SETTINGS,
CPDFToolbarAction.DOCUMENT_EDITOR,
CPDFToolbarAction.DOCUMENT_INFO,
CPDFToolbarAction.WATERMARK,
CPDFToolbarAction.SECURITY,
CPDFToolbarAction.FLATTENED,
CPDFToolbarAction.SAVE,
CPDFToolbarAction.SHARE,
CPDFToolbarAction.OPEN_DOCUMENT,
CPDFToolbarAction.SNIP,
]
}
})}
/>2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Custom Menus
In version 2.6.0 and higher, you can add custom menu options using the customToolbarLeftItems, customToolbarRightItems, and customMoreMenuItems properties.
Two customization methods are provided:
- Modify the icon and title of existing menu options
- Add completely custom menu options
Here is a configuration example:
const customToolbarConfig: CPDFToolbarConfig = {
mainToolbarTitleVisible: false,
customToolbarLeftItems: [
{
action: "back",
icon: "ic_test_back",
},
{
action: "custom", // Custom button, must be custom
identifier: "custom_editor", // Custom identifier, required
icon: "ic_test_edit", // Custom icon
},
],
customToolbarRightItems: [
{
action: "bota",
icon: "ic_test_book",
},
{
action: "custom",
identifier: "custom_text_search",
icon: "ic_test_search",
},
{
action: "menu",
icon: "ic_test_more",
},
],
customMoreMenuItems: [
{
action: "viewSettings",
title: "Custom View Settings",
icon: "ic_test_setting",
},
{
action: "custom", // Custom button, must be custom
title: "Custom Share", // Option name in more menu
icon: "ic_test_share", // Icon in more menu
identifier: "custom_share", // Custom menu identifier, required
}
],
};2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Parameter Description
| Parameter | Description |
|---|---|
| action | Required parameter, specifies the menu option to customize, refer to CPDFToolbarAction. |
| identifier | Required parameter (for custom menus only), unique identifier for the custom menu option. |
| icon | Optional parameter, specifies the icon for the menu option. Supports local resource image names or file paths. |
| title | Optional parameter, specifies the title text for the menu option. Only takes effect in more menu. |
Toolbar Configuration Fields
| Field | Description |
|---|---|
toolbarLeftItems | Built-in actions displayed on the left side of the main toolbar. |
toolbarRightItems | Built-in actions displayed on the right side of the main toolbar. |
availableMenus | Built-in actions displayed inside the more menu opened by menu. |
customToolbarLeftItems | Custom or overridden items displayed on the left side of the main toolbar. |
customToolbarRightItems | Custom or overridden items displayed on the right side of the main toolbar. |
customMoreMenuItems | Custom or overridden items displayed inside the more menu. |
mainToolbarVisible | Shows or hides the whole main toolbar. |
mainToolbarTitleVisible | Shows or hides the mode-switch title and entry in the main toolbar. |
annotationToolbarVisible | Shows or hides the annotation toolbar in annotation mode. |
contentEditorToolbarVisible | Shows or hides the content editor toolbar in content editor mode. |
formToolbarVisible | Shows or hides the form toolbar in forms mode. |
signatureToolbarVisible | Shows or hides the signature toolbar in signatures mode. |
showInkToggleButton | Shows or hides the ink toggle button in the annotation toolbar. |
Adding Custom Menu Click Events
Only when using action = custom for custom menu options, you need to handle click events through the onCustomToolbarItemTapped callback:
<CPDFReaderView
ref={pdfReaderRef}
document={samplePDF}
configuration={ComPDFKit.getDefaultConfig({
toolbarConfig: customToolbarConfig,
})}
onIOSClickBackPressed={handleBack}
onCustomToolbarItemTapped={(identifier) =>{
if (identifier === 'custom_text_search') {
console.log('Custom Search Action Tapped');
// Handle custom search operation
} else if (identifier === 'custom_editor') {
console.log('Custom Editor Action Tapped');
// Handle custom editor operation
} else if (identifier === 'custom_share') {
console.log('Custom Share Action Tapped');
// Handle custom share operation
}
}}
/>2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Adding Custom Icons
To customize menu icons, you need to add icon resources separately for Android and iOS platforms:
- Android: Place icon files (such as
ic_test_search.png) in theandroid/app/src/main/res/drawabledirectory. - iOS: Add icon files (such as
ic_test_search.png) to theios/Runner/Assets.xcassetsasset catalog.



