How can I help you?
Add a Save Button to the Built-in Toolbar in React PDF Viewer
25 Feb 20267 minutes to read
PDF Viewer supports customizing toolbar items, including adding, showing, hiding, enabling, and disabling items.
-
Save button: The Save button can be defined using CustomToolbarItemModel and included alongside existing items via ToolbarSettings. Handle the click action using
toolbarclick. -
Show or hide: The Save button can be shown or hidden using ToolbarSettings. Predefined items are listed under
ToolbarItem. -
Enable or disable: The Save button can be enabled or disabled using
enabletoolbaritem.
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import './index.css';
import { PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView,
ThumbnailView, Print, TextSelection, Annotation, TextSearch, FormFields, FormDesigner, Inject} from '@syncfusion/ej2-react-pdfviewer';
import { ComboBox } from "@syncfusion/ej2-dropdowns";
import { TextBox } from "@syncfusion/ej2-inputs";
export function App() {
// Helper: Add OnCreateSearch outside the App function
// The sample below uses an OnCreateSearch helper to add an icon; place it in module scope.
function OnCreateSearch() {
this.addIcon('prepend', 'e-icons e-search');
}
var toolItem1 = {
prefixIcon: 'e-icons e-save',
id: 'download',
text: 'Save',
tooltipText: 'Save button',
align: 'Left'
};
function toolbarClick(args){
if (args.item && args.item.id === 'download') {
viewer.download();
}
};
return (<div>
<div className='control-section'>
<PdfViewerComponent
id="container"
documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
resourceUrl="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib"
toolbarSettings={{ showTooltip : true, toolbarItems: ['OpenOption', toolItem1, 'PageNavigationTool', 'MagnificationTool', 'PanTool', 'SelectionTool', 'SearchOption', 'PrintOption', 'UndoRedoTool', 'AnnotationEditTool', 'FormDesignerEditTool', 'CommentTool', 'SubmitForm']}}
toolbarClick={toolbarClick}
style={{ 'height': '640px' }}>
{/* Inject the required services */}
<Inject services={[ Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, BookmarkView, ThumbnailView,
Print, TextSelection, TextSearch, FormFields, FormDesigner]} />
</PdfViewerComponent>
</div>
</div>);
}
const root = ReactDOM.createRoot(document.getElementById('sample'));
root.render(<App />);import * as ReactDOM from 'react-dom';
import * as React from 'react';
import './index.css';
import { PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView,
ThumbnailView, Print, TextSelection, Annotation, TextSearch, FormFields, FormDesigner, Inject} from '@syncfusion/ej2-react-pdfviewer';
import { ComboBox } from "@syncfusion/ej2-dropdowns";
import { TextBox } from "@syncfusion/ej2-inputs";
export function App() {
// Add OnCreateSearch outside the App function
function OnCreateSearch() {
this.addIcon('prepend', 'e-icons e-search');
}
var toolItem1 = {
prefixIcon: 'e-icons e-save',
id: 'download',
text: 'Save',
tooltipText: 'Save button',
align: 'Left'
};
function toolbarClick(args){
var viewer = document.getElementById('container').ej2_instances[0];
if (args.item && args.item.id === 'download') {
viewer.download();
}
};
return (<div>
<div className='control-section'>
<PdfViewerComponent
id="container"
documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
serviceUrl="https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer"
toolbarSettings={{ showTooltip : true, toolbarItems: ['OpenOption', toolItem1, 'PageNavigationTool', 'MagnificationTool', toolItem3, 'PanTool', 'SelectionTool', 'SearchOption', 'PrintOption', 'UndoRedoTool', 'AnnotationEditTool', 'FormDesignerEditTool', 'CommentTool', 'SubmitForm']}}
toolbarClick={toolbarClick}
style={{ 'height': '640px' }}>
{/* Inject the required services */}
<Inject services={[ Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, BookmarkView, ThumbnailView,
Print, TextSelection, TextSearch, FormFields, FormDesigner]} />
</PdfViewerComponent>
</div>
</div>);
}
const root = ReactDOM.createRoot(document.getElementById('sample'));
root.render(<App />);NOTE
Default toolbar items include: [‘OpenOption’, ‘PageNavigationTool’, ‘MagnificationTool’, ‘PanTool’, ‘SelectionTool’, ‘SearchOption’, ‘PrintOption’, ‘DownloadOption’, ‘UndoRedoTool’, ‘AnnotationEditTool’, ‘FormDesignerEditTool’, ‘CommentTool’, ‘SubmitForm’]
Align property
Specifies the alignment of the Save button within the toolbar:
- Left: aligns the item to the left side of the toolbar.
- Right: aligns the item to the right side of the toolbar.
Tooltip property
Sets the tooltip text for the Save button; the tooltip appears on hover.
CssClass property
Applies custom CSS classes to the Save button for styling.
Prefix property
Sets the CSS class or icon to display before the Save button text.
ID property
The id property within a CustomToolbarItemModel is required and uniquely identifies each toolbar item for configuration and interaction.
When defining or customizing toolbar items, assign a specific, descriptive id to each item. These properties are commonly used when defining custom toolbar items with CustomToolbarItemModel in the context of Syncfusion PDF Viewer. When configuring the toolbar using the ToolbarSettings property, include these properties to customize appearance and behavior.
NOTE
When customizing the Save button, icons or text can be used based on design preference.