|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Add save button in toolbar in React Pdfviewer component | Syncfusion |
| 4 | +description: Learn here all about Add Save button in Syncfusion React Pdfviewer component of Syncfusion Essential JS 2 and more. |
| 5 | +control: Toolbar |
| 6 | +platform: ej2-react |
| 7 | +documentation: ug |
| 8 | +domainurl: ##DomainURL## |
| 9 | +--- |
| 10 | + |
| 11 | +# Add Save button in Built-In Toolbar |
| 12 | + |
| 13 | +PDF Viewer allows you to customize(add, show, hide, enable, and disable) existing items in a toolbar. |
| 14 | + |
| 15 | +* Save Button - New `save` button-item can defined by [**CustomToolbarItemModel**](https://ej2.syncfusion.com/react/documentation/api/pdfviewer/customToolbarItemModel/) and with existing items in [**ToolbarSettings**](https://ej2.syncfusion.com/react/documentation/api/pdfviewer/toolbarSettings/) property. Newly added save button-item click action can be defined in [`toolbarclick`](https://ej2.syncfusion.com/react/documentation/api/toolbar/clickEventArgs/). |
| 16 | + |
| 17 | +* Show, Hide - `Save` button-item can be shown or hidden using the [`ToolbarSettings`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer/toolbarSettings/) property. Pre-defined toolbar items are available with [`ToolbarItem`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer/toolbarItem/). |
| 18 | + |
| 19 | +* Enable, Disable - `Save` button-item can be enabled or disable using [`enabletoolbaritem`](https://ej2.syncfusion.com/react/documentation/api/pdfviewer/toolbar/#enabletoolbaritem) |
| 20 | + |
| 21 | +{% tabs %} |
| 22 | +{% highlight js tabtitle="Standalone" %} |
| 23 | +{% raw %} |
| 24 | + |
| 25 | +import * as ReactDOM from 'react-dom'; |
| 26 | +import * as React from 'react'; |
| 27 | +import './index.css'; |
| 28 | +import { PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, |
| 29 | + ThumbnailView, Print, TextSelection, Annotation, TextSearch, FormFields, FormDesigner, Inject} from '@syncfusion/ej2-react-pdfviewer'; |
| 30 | +import { ComboBox } from "@syncfusion/ej2-dropdowns"; |
| 31 | +import { TextBox } from "@syncfusion/ej2-inputs"; |
| 32 | + |
| 33 | +export function App() { |
| 34 | + |
| 35 | +// Add OnCreateSearch outside the App function |
| 36 | +function OnCreateSearch() { |
| 37 | + this.addIcon('prepend', 'e-icons e-search'); |
| 38 | +} |
| 39 | + |
| 40 | + var toolItem1 = { |
| 41 | + prefixIcon: 'e-icons e-save', |
| 42 | + id: 'download', |
| 43 | + text: 'Save', |
| 44 | + tooltipText: 'Save button', |
| 45 | + align: 'Left' |
| 46 | +}; |
| 47 | + |
| 48 | + function toolbarClick(args){ |
| 49 | + if (args.item && args.item.id === 'download') { |
| 50 | + viewer.download(); |
| 51 | + } |
| 52 | + }; |
| 53 | +return (<div> |
| 54 | + <div className='control-section'> |
| 55 | + <PdfViewerComponent |
| 56 | + id="container" |
| 57 | + documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf" |
| 58 | + resourceUrl="https://cdn.syncfusion.com/ej2/24.1.41/dist/ej2-pdfviewer-lib" |
| 59 | + toolbarSettings={{ showTooltip : true, toolbarItems: ['OpenOption', toolItem1, 'PageNavigationTool', 'MagnificationTool', 'PanTool', 'SelectionTool', 'SearchOption', 'PrintOption', 'UndoRedoTool', 'AnnotationEditTool', 'FormDesignerEditTool', 'CommentTool', 'SubmitForm']}} |
| 60 | + toolbarClick={toolbarClick} |
| 61 | + style={{ 'height': '640px' }}> |
| 62 | + {/* Inject the required services */} |
| 63 | + <Inject services={[ Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, BookmarkView, ThumbnailView, |
| 64 | + Print, TextSelection, TextSearch, FormFields, FormDesigner]} /> |
| 65 | + </PdfViewerComponent> |
| 66 | + </div> |
| 67 | +</div>); |
| 68 | +} |
| 69 | +const root = ReactDOM.createRoot(document.getElementById('sample')); |
| 70 | +root.render(<App />); |
| 71 | + |
| 72 | +{% endraw %} |
| 73 | +{% endhighlight %} |
| 74 | +{% highlight js tabtitle="Server-Backed" %} |
| 75 | +{% raw %} |
| 76 | + |
| 77 | +import * as ReactDOM from 'react-dom'; |
| 78 | +import * as React from 'react'; |
| 79 | +import './index.css'; |
| 80 | +import { PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, |
| 81 | + ThumbnailView, Print, TextSelection, Annotation, TextSearch, FormFields, FormDesigner, Inject} from '@syncfusion/ej2-react-pdfviewer'; |
| 82 | +import { ComboBox } from "@syncfusion/ej2-dropdowns"; |
| 83 | +import { TextBox } from "@syncfusion/ej2-inputs"; |
| 84 | + |
| 85 | +export function App() { |
| 86 | + |
| 87 | +// Add OnCreateSearch outside the App function |
| 88 | +function OnCreateSearch() { |
| 89 | + this.addIcon('prepend', 'e-icons e-search'); |
| 90 | +} |
| 91 | + |
| 92 | + var toolItem1 = { |
| 93 | + prefixIcon: 'e-icons e-save', |
| 94 | + id: 'download', |
| 95 | + text: 'Save', |
| 96 | + tooltipText: 'Save button', |
| 97 | + align: 'Left' |
| 98 | +}; |
| 99 | + |
| 100 | + function toolbarClick(args){ |
| 101 | + var viewer = document.getElementById('container').ej2_instances[0]; |
| 102 | + if (args.item && args.item.id === 'download') { |
| 103 | + viewer.download(); |
| 104 | + } |
| 105 | + }; |
| 106 | +return (<div> |
| 107 | + <div className='control-section'> |
| 108 | + <PdfViewerComponent |
| 109 | + id="container" |
| 110 | + documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf" |
| 111 | + serviceUrl="https://ej2services.syncfusion.com/production/web-services/api/pdfviewer" |
| 112 | + toolbarSettings={{ showTooltip : true, toolbarItems: ['OpenOption', toolItem1, 'PageNavigationTool', 'MagnificationTool', toolItem3, 'PanTool', 'SelectionTool', 'SearchOption', 'PrintOption', 'UndoRedoTool', 'AnnotationEditTool', 'FormDesignerEditTool', 'CommentTool', 'SubmitForm']}} |
| 113 | + toolbarClick={toolbarClick} |
| 114 | + style={{ 'height': '640px' }}> |
| 115 | + {/* Inject the required services */} |
| 116 | + <Inject services={[ Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, BookmarkView, ThumbnailView, |
| 117 | + Print, TextSelection, TextSearch, FormFields, FormDesigner]} /> |
| 118 | + </PdfViewerComponent> |
| 119 | + </div> |
| 120 | +</div>); |
| 121 | +} |
| 122 | +const root = ReactDOM.createRoot(document.getElementById('sample')); |
| 123 | +root.render(<App />); |
| 124 | + |
| 125 | +{% endraw %} |
| 126 | +{% endhighlight %} |
| 127 | +{% endtabs %} |
| 128 | + |
| 129 | +>Note : Default value of toolbar items is ['OpenOption', 'PageNavigationTool','MagnificationTool', 'PanTool', 'SelectionTool', 'SearchOption', 'PrintOption', 'DownloadOption','UndoRedoTool', 'AnnotationEditTool', 'FormDesignerEditTool', 'CommentTool', 'SubmitForm'] |
| 130 | +
|
| 131 | +### Align Property |
| 132 | + |
| 133 | +The align property is used to specify the alignment of a `save` button-item within the toolbar. |
| 134 | + |
| 135 | +`Left`: Aligns the item to the left side of the toolbar. |
| 136 | +`Right`: Aligns the item to the right side of the toolbar. |
| 137 | + |
| 138 | +### Tooltip Property |
| 139 | + |
| 140 | +The tooltip property is used to set the tooltip text for a `save` button-item. Tooltip provides additional information when a user hovers over the item. |
| 141 | + |
| 142 | +### CssClass Property |
| 143 | + |
| 144 | +The cssClass property is used to apply custom CSS classes to a `save` button-item. It allows custom styling of the `save` button-item. |
| 145 | + |
| 146 | +### Prefix Property |
| 147 | + |
| 148 | +The prefix property is used to set the CSS class or icon that should be added as a prefix to the existing content of the toolbar item. |
| 149 | + |
| 150 | +### ID Property |
| 151 | + |
| 152 | +The id property within a CustomToolbarItemModel is a compulsory attribute that plays a vital role in toolbar customization. It serves as a unique identifier for each toolbar item, facilitating distinct references and interactions. |
| 153 | + |
| 154 | +When defining or customizing toolbar items, it is mandatory to assign a specific and descriptive id to each item. |
| 155 | +These properties are commonly used when defining custom toolbar items with the `CustomToolbarItemModel`` in the context of Syncfusion PDF Viewer. When configuring the toolbar using the `ToolbarSettings`` property, you can include these properties to customize the appearance and behavior of each toolbar item. |
| 156 | + |
| 157 | +N> When customizing `save` button-item, you have the flexibility to include either icons or text based on your design preference. |
| 158 | + |
| 159 | +[View sample in GitHub](https://github.com/SyncfusionExamples/react-pdf-viewer-examples/tree/master/How%20to) |
0 commit comments