How can I help you?
Toolbar in Vue PDF Viewer
28 Feb 202624 minutes to read
The built-in toolbar provides quick access to essential PDF viewing features including page navigation, text search, zoom controls, printing, and downloading. You can customize the toolbar by showing/hiding items, adding custom buttons, or creating a completely custom interface.
The following table shows the available built-in toolbar items:
| Option | Description |
|---|---|
| OpenOption | Open and load PDF documents from local or remote sources |
| PageNavigationTool | Navigate between pages (first, last, next, previous, go to specific page) |
| MagnificationTool | Zoom controls (zoom in, zoom out, fit to page, fit to width, custom zoom) |
| PanTool | Pan/move the PDF page when zoomed in |
| SelectionTool | Enable text selection mode for copying content |
| SearchOption | Search for text within the PDF document |
| PrintOption | Print the current PDF document |
| DownloadOption | Download the PDF document to the local file system |
| UndoRedoTool | Undo and redo annotation changes |
| AnnotationEditTool | Toggle annotation editing mode |
| FormDesignerEditTool | Toggle form field design/editing mode |
Control toolbar visibility
Control whether the toolbar is displayed using the enableToolbar property or the showToolbar() method. You can disable the toolbar initially or toggle it programmatically based on user interactions.
Using the enableToolbar property
<template>
<div id="app">
<ejs-pdfviewer id="pdfViewer" :documentPath="documentPath" :enableToolbar="false" :resourceUrl="resourceUrl">
</ejs-pdfviewer>
</div>
</template>
<script setup>
import {
PdfViewerComponent as EjsPdfviewer, Toolbar, Magnification, Navigation, LinkAnnotation,
BookmarkView, ThumbnailView, Print, TextSelection, TextSearch,
Annotation, FormDesigner, FormFields
} from '@syncfusion/ej2-vue-pdfviewer';
import { provide } from 'vue';
const documentPath = "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf";
const resourceUrl = "https://cdn.syncfusion.com/ej2/23.1.43/dist/ej2-pdfviewer-lib";
provide('PdfViewer', [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, Annotation,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner])
</script><template>
<div id="app">
<ejs-pdfviewer id="pdfViewer" :documentPath="documentPath" :enableToolbar="false" :resourceUrl="resourceUrl">
</ejs-pdfviewer>
</div>
</template>
<script>
import {
PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation,
BookmarkView, ThumbnailView, Print, TextSelection, TextSearch,
Annotation, FormDesigner, FormFields
} from '@syncfusion/ej2-vue-pdfviewer';
export default {
name: "App",
components: {
"ejs-pdfviewer": PdfViewerComponent
},
data() {
return {
documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf",
resourceUrl: "https://cdn.syncfusion.com/ej2/23.1.43/dist/ej2-pdfviewer-lib",
};
},
provide: {
PdfViewer: [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, Annotation,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner]
}
}
</script>NOTE
To set up the server-backed PDF Viewer in the app.vue file, include the following
serviceUrl:
serviceUrl: “https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer”
Within thetemplate, configure the PDF Viewer by adding the:serviceUrl="serviceUrl"attribute inside the <div> element.
Using the showToolbar() method
Programmatically show or hide the toolbar at runtime using the showToolbar() method:
<template>
<div id="app">
<button v-on:click="showToolbarClicked">showToolbarClicked</button>
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath" :documentLoad="documentLoad"
:resourceUrl="resourceUrl">
</ejs-pdfviewer>
</div>
</template>
<script setup>
import {
PdfViewerComponent as EjsPdfviewer, Toolbar, Magnification, Navigation, LinkAnnotation,
BookmarkView, ThumbnailView, Print, TextSelection, TextSearch,
Annotation, FormDesigner, FormFields
} from '@syncfusion/ej2-vue-pdfviewer';
import { provide, ref } from 'vue';
const pdfviewer = ref(null);
const documentPath = "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf";
const resourceUrl = "https://cdn.syncfusion.com/ej2/23.1.43/dist/ej2-pdfviewer-lib";
provide('PdfViewer', [Toolbar, Magnification, Navigation, LinkAnnotation, Annotation, BookmarkView,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner])
const showToolbarClicked = function (args) {
pdfviewer.value.ej2Instances.toolbar.showToolbar(false);
}
</script><template>
<div id="app">
<button v-on:click="showToolbarClicked">showToolbarClicked</button>
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath" :documentLoad="documentLoad"
:resourceUrl="resourceUrl">
</ejs-pdfviewer>
</div>
</template>
<script>
import {
PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation,
BookmarkView, ThumbnailView, Print, TextSelection, TextSearch,
Annotation, FormDesigner, FormFields
} from '@syncfusion/ej2-vue-pdfviewer';
export default {
name: "App",
components: {
"ejs-pdfviewer": PdfViewerComponent
},
data() {
return {
documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf",
resourceUrl: "https://cdn.syncfusion.com/ej2/23.1.43/dist/ej2-pdfviewer-lib"
};
},
provide: {
PdfViewer: [Toolbar, Magnification, Navigation, LinkAnnotation, Annotation, BookmarkView,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner]
},
methods: {
showToolbarClicked: function (args) {
this.$refs.pdfviewer.ej2Instances.toolbar.showToolbar(false);
}
}
}
</script>NOTE
To set up the server-backed PDF Viewer in the app.vue file, include the following
serviceUrl:
serviceUrl: “https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer”
Within thetemplate, configure the PDF Viewer by adding the:serviceUrl="serviceUrl"attribute inside the <div> element.
Customize toolbar items
Control which toolbar items are displayed using the toolbarSettings property or manage individual items at runtime with the showToolbarItem() method.
Using toolbarSettings to configure items
<template>
<div id="app">
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath" :enableTextSelection="false"
:toolbarSettings="toolbarSettings" :resourceUrl="resourceUrl">
</ejs-pdfviewer>
</div>
</template>
<script setup>
import {
PdfViewerComponent as EjsPdfviewer, Toolbar, Magnification, Navigation, LinkAnnotation,
BookmarkView, ThumbnailView, Print, TextSelection, TextSearch,
Annotation, FormDesigner, FormFields
} from '@syncfusion/ej2-vue-pdfviewer';
import { provide } from 'vue';
const documentPath = "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf";
const resourceUrl = "https://cdn.syncfusion.com/ej2/23.1.43/dist/ej2-pdfviewer-lib";
const toolbarSettings = { showTooltip: true, toolbarItems: ['OpenOption', 'UndoRedoTool', 'PageNavigationTool', 'MagnificationTool', 'PanTool', 'SelectionTool', 'CommentTool', 'SubmitForm', 'AnnotationEditTool', 'FormDesignerEditTool', 'FreeTextAnnotationOption', 'InkAnnotationOption', 'ShapeAnnotationOption', 'StampAnnotation', 'SignatureOption', 'SearchOption', 'PrintOption', 'DownloadOption'], annotationToolbarItems: ['HighlightTool', 'UnderlineTool', 'StrikethroughTool', 'ColorEditTool', 'OpacityEditTool', 'AnnotationDeleteTool', 'StampAnnotationTool', 'HandWrittenSignatureTool', 'InkAnnotationTool', 'ShapeTool', 'CalibrateTool', 'StrokeColorEditTool', 'ThicknessEditTool', 'FreeTextAnnotationTool', 'FontFamilyAnnotationTool', 'FontSizeAnnotationTool', 'FontStylesAnnotationTool', 'FontAlignAnnotationTool', 'FontColorAnnotationTool', 'CommentPanelTool'], formDesignerToolbarItems: ['TextboxTool', 'PasswordTool', 'CheckBoxTool', 'RadioButtonTool', 'DropdownTool', 'ListboxTool', 'DrawSignatureTool', 'DeleteTool'] };
provide('PdfViewer', [Toolbar, Magnification, Navigation, LinkAnnotation, Annotation, BookmarkView,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner])
</script><template>
<div id="app">
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath" :enableTextSelection="false"
:toolbarSettings="toolbarSettings" :resourceUrl="resourceUrl">
</ejs-pdfviewer>
</div>
</template>
<script>
import {
PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation,
BookmarkView, ThumbnailView, Print, TextSelection, TextSearch,
Annotation, FormDesigner, FormFields
} from '@syncfusion/ej2-vue-pdfviewer';
export default {
name: "App",
components: {
"ejs-pdfviewer": PdfViewerComponent
},
data() {
return {
documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf",
resourceUrl: "https://cdn.syncfusion.com/ej2/23.1.43/dist/ej2-pdfviewer-lib",
toolbarSettings: { showTooltip: true, toolbarItems: ['OpenOption', 'UndoRedoTool', 'PageNavigationTool', 'MagnificationTool', 'PanTool', 'SelectionTool', 'CommentTool', 'SubmitForm', 'AnnotationEditTool', 'FormDesignerEditTool', 'FreeTextAnnotationOption', 'InkAnnotationOption', 'ShapeAnnotationOption', 'StampAnnotation', 'SignatureOption', 'SearchOption', 'PrintOption', 'DownloadOption'], annotationToolbarItems: ['HighlightTool', 'UnderlineTool', 'StrikethroughTool', 'ColorEditTool', 'OpacityEditTool', 'AnnotationDeleteTool', 'StampAnnotationTool', 'HandWrittenSignatureTool', 'InkAnnotationTool', 'ShapeTool', 'CalibrateTool', 'StrokeColorEditTool', 'ThicknessEditTool', 'FreeTextAnnotationTool', 'FontFamilyAnnotationTool', 'FontSizeAnnotationTool', 'FontStylesAnnotationTool', 'FontAlignAnnotationTool', 'FontColorAnnotationTool', 'CommentPanelTool'], formDesignerToolbarItems: ['TextboxTool', 'PasswordTool', 'CheckBoxTool', 'RadioButtonTool', 'DropdownTool', 'ListboxTool', 'DrawSignatureTool', 'DeleteTool'] }
};
},
provide: {
PdfViewer: [Toolbar, Magnification, Navigation, LinkAnnotation, Annotation, BookmarkView,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner]
}
}
</script>NOTE
To set up the server-backed PDF Viewer in the app.vue file, include the following
serviceUrl:
serviceUrl: “https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer”
Within thetemplate, configure the PDF Viewer by adding the:serviceUrl="serviceUrl"attribute inside the <div> element.
Using showToolbarItem() to toggle items
Show or hide specific toolbar items at runtime after the toolbar is initialized:
<template>
<div id="app">
<button v-on:click="showToolbarClicked">ShowToolbar</button>
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath" :documentLoad="documentLoad"
:resourceUrl="resourceUrl">
</ejs-pdfviewer>
</div>
</template>
<script setup>
import {
PdfViewerComponent as EjsPdfviewer, Toolbar, Magnification, Navigation, LinkAnnotation,
BookmarkView, ThumbnailView, Print, TextSelection, TextSearch,
Annotation, FormDesigner, FormFields
} from '@syncfusion/ej2-vue-pdfviewer';
import { provide, ref } from 'vue';
const pdfviewer = ref(null);
const documentPath = "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf";
const resourceUrl = "https://cdn.syncfusion.com/ej2/23.1.43/dist/ej2-pdfviewer-lib";
provide('PdfViewer', [Toolbar, Magnification, Navigation, LinkAnnotation, Annotation, BookmarkView,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner])
const showToolbarClicked = function (args) {
pdfviewer.ej2Instances.toolbar.showToolbarItem(["OpenOption"], false);
}
</script><template>
<div id="app">
<button v-on:click="showToolbarClicked">ShowToolbar</button>
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath" :documentLoad="documentLoad"
:resourceUrl="resourceUrl">
</ejs-pdfviewer>
</div>
</template>
<script>
import {
PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation,
BookmarkView, ThumbnailView, Print, TextSelection, TextSearch,
Annotation, FormDesigner, FormFields
} from '@syncfusion/ej2-vue-pdfviewer';
export default {
name: "App",
components: {
"ejs-pdfviewer": PdfViewerComponent
},
data() {
return {
documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf",
resourceUrl: "https://cdn.syncfusion.com/ej2/23.1.43/dist/ej2-pdfviewer-lib"
};
},
provide: {
PdfViewer: [Toolbar, Magnification, Navigation, LinkAnnotation, Annotation, BookmarkView,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner]
},
methods: {
showToolbarClicked: function (args) {
this.$refs.pdfviewer.ej2Instances.toolbar.showToolbarItem(["OpenOption"], false);
}
}
}
</script>NOTE
To set up the server-backed PDF Viewer in the app.vue file, include the following
serviceUrl:
serviceUrl: “https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer”
Within thetemplate, configure the PDF Viewer by adding the:serviceUrl="serviceUrl"attribute inside the <div> element.
Customize Built-In Toolbar
PDF Viewer allows you to customize(add, show, hide, enable, and disable) existing items in a toolbar.
-
Add - New items can defined by CustomToolbarItemModel and with existing items in ToolbarSettings property. Newly added item click action can be defined in
toolbarclick. -
Show, Hide - Existing items can be shown or hidden using the
ToolbarSettingsproperty. Pre-defined toolbar items are available withToolbarItem. -
Enable, Disable - Toolbar items can be enabled or disable using
enabletoolbaritem
<template>
<div id="app">
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath" :resourceUrl="resourceUrl"
:toolbarClick="toolbarClick" :OnCreateSearch="OnCreateSearch" :toolbarSettings="toolbarSettings">
</ejs-pdfviewer>
</div>
</template>
<script setup>
import {
PdfViewerComponent as EjsPdfviewer, Toolbar, Magnification, Navigation, LinkAnnotation,
BookmarkView, ThumbnailView, Print, TextSelection, TextSearch,
Annotation, FormDesigner, FormFields
} from '@syncfusion/ej2-vue-pdfviewer';
import { ComboBox } from "@syncfusion/ej2-dropdowns";
import { TextBox } from "@syncfusion/ej2-inputs";
import { provide, ref } from 'vue';
const pdfviewer = ref(null);
// Move the toolItem declaration inside the data function
let toolItem1 = {
prefixIcon: 'e-icons e-paste',
id: 'print',
tooltipText: 'Custom toolbar item',
align: 'left'
};
let toolItem2 = {
id: 'download',
text: 'Save',
tooltipText: 'Custom toolbar item',
align: 'right'
};
let LanguageList = ['Typescript', 'Javascript', 'Angular', 'C#', 'C', 'Python'];
let toolItem3 = {
type: 'Input',
tooltipText: 'Language List',
cssClass: 'percentage',
align: 'Left',
id: 'dropdown',
template: new ComboBox({ width: 100, value: 'TypeScript', dataSource: LanguageList, popupWidth: 85, showClearButton: false, readonly: false })
};
let toolItem4 = {
type: 'Input',
tooltipText: 'Text',
align: 'Right',
cssClass: 'find',
id: 'textbox',
template: new TextBox({ width: 125, placeholder: 'Type Here' })
}
const documentPath = "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf";
const resourceUrl = "https://cdn.syncfusion.com/ej2/24.1.41/dist/ej2-pdfviewer-lib";
const toolbarSettings = {
toolbarItems: [toolItem1, toolItem2, 'OpenOption', 'PageNavigationTool', 'MagnificationTool', toolItem3, 'PanTool', 'SelectionTool', 'SearchOption', 'PrintOption', 'DownloadOption', 'UndoRedoTool', 'AnnotationEditTool', 'FormDesignerEditTool', toolItem4, 'CommentTool', 'SubmitForm']
}
provide('PdfViewer', [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView,
Print, TextSelection, TextSearch, Annotation, FormDesigner, FormFields]);
const toolbarClick = function (args) {
if (args.item && args.item.id === 'print') {
pdfviewer.value.ej2Instances.printModule.print();
}
else if (args.item && args.item.id === 'download') {
pdfviewer.value.ej2Instances.download();
}
}
</script><template>
<div id="app">
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath"
:resourceUrl="resourceUrl" :toolbarClick="toolbarClick" :OnCreateSearch="OnCreateSearch"
:toolbarSettings="toolbarSettings">
</ejs-pdfviewer>
</div>
</template>
<script>
import {
PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation,
BookmarkView, ThumbnailView, Print, TextSelection, TextSearch,
Annotation, FormDesigner, FormFields
} from '@syncfusion/ej2-vue-pdfviewer';
import { ComboBox } from "@syncfusion/ej2-dropdowns";
import { TextBox } from "@syncfusion/ej2-inputs";
export default {
name: "App",
components: {
"ejs-pdfviewer": PdfViewerComponent
},
data() {
// Move the toolItem declaration inside the data function
let toolItem1 = {
prefixIcon: 'e-icons e-paste',
id: 'print',
tooltipText: 'Custom toolbar item',
align: 'left'
};
let toolItem2 = {
id: 'download',
text: 'Save',
tooltipText: 'Custom toolbar item',
align: 'right'
};
let LanguageList = ['Typescript', 'Javascript', 'Angular', 'C#', 'C', 'Python'];
let toolItem3 = {
type: 'Input',
tooltipText: 'Language List',
cssClass: 'percentage',
align: 'Left',
id: 'dropdown',
template: new ComboBox({ width: 100, value: 'TypeScript', dataSource: LanguageList, popupWidth: 85, showClearButton: false, readonly: false })
};
let toolItem4 = {
type: 'Input',
tooltipText: 'Text',
align: 'Right',
cssClass: 'find',
id: 'textbox',
template: new TextBox({ width: 125, placeholder: 'Type Here' })
}
return {
documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf",
resourceUrl: "https://cdn.syncfusion.com/ej2/24.1.41/dist/ej2-pdfviewer-lib",
toolbarSettings: {
toolbarItems: [toolItem1, toolItem2, 'OpenOption', 'PageNavigationTool', 'MagnificationTool', toolItem3, 'PanTool', 'SelectionTool', 'SearchOption', 'PrintOption', 'DownloadOption', 'UndoRedoTool', 'AnnotationEditTool', 'FormDesignerEditTool', toolItem4, 'CommentTool', 'SubmitForm']
}
};
},
provide: {
PdfViewer: [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView,
Print, TextSelection, TextSearch, Annotation, FormDesigner, FormFields]
},
methods: {
toolbarClick: function (args) {
if (args.item && args.item.id === 'print') {
this.$refs.pdfviewer.ej2Instances.printModule.print();
}
else if (args.item && args.item.id === 'download') {
this.$refs.pdfviewer.ej2Instances.download();
}
},
}
}
</script><template>
<div id="app">
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath" :serviceUrl="serviceUrl"
:toolbarClick="toolbarClick" :OnCreateSearch="OnCreateSearch" :toolbarSettings="toolbarSettings">
</ejs-pdfviewer>
</div>
</template>
<script setup>
import {
PdfViewerComponent as EjsPdfviewer, Toolbar, Magnification, Navigation, LinkAnnotation,
BookmarkView, ThumbnailView, Print, TextSelection, TextSearch,
Annotation, FormDesigner, FormFields
} from '@syncfusion/ej2-vue-pdfviewer';
import { ComboBox } from "@syncfusion/ej2-dropdowns";
import { TextBox } from "@syncfusion/ej2-inputs";
import { provide, ref } from 'vue';
const pdfviewer = ref(null);
// Move the toolItem declaration inside the data function
let toolItem1 = {
prefixIcon: 'e-icons e-paste',
id: 'print',
tooltipText: 'Custom toolbar item',
align: 'left'
};
let toolItem2 = {
id: 'download',
text: 'Save',
tooltipText: 'Custom toolbar item',
align: 'right'
};
let LanguageList = ['Typescript', 'Javascript', 'Angular', 'C#', 'C', 'Python'];
let toolItem3 = {
type: 'Input',
tooltipText: 'Language List',
cssClass: 'percentage',
align: 'Left',
id: 'dropdown',
template: new ComboBox({ width: 100, value: 'TypeScript', dataSource: LanguageList, popupWidth: 85, showClearButton: false, readonly: false })
};
let toolItem4 = {
type: 'Input',
tooltipText: 'Text',
align: 'Right',
cssClass: 'find',
id: 'textbox',
template: new TextBox({ width: 125, placeholder: 'Type Here' })
}
const documentPath = "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf";
const serviceUrl = "https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer";
const toolbarSettings = {
toolbarItems: [toolItem1, toolItem2, 'OpenOption', 'PageNavigationTool', 'MagnificationTool', toolItem3, 'PanTool', 'SelectionTool', 'SearchOption', 'PrintOption', 'DownloadOption', 'UndoRedoTool', 'AnnotationEditTool', 'FormDesignerEditTool', toolItem4, 'CommentTool', 'SubmitForm']
}
provide('PdfViewer', [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView,
Print, TextSelection, TextSearch, Annotation, FormDesigner, FormFields]);
const toolbarClick = function (args) {
if (args.item && args.item.id === 'print') {
this.$refs.pdfviewer.ej2Instances.printModule.print();
}
else if (args.item && args.item.id === 'download') {
this.$refs.pdfviewer.ej2Instances.download();
}
}
</script><template>
<div id="app">
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath" :serviceUrl="serviceUrl" :toolbarClick="toolbarClick" :OnCreateSearch="OnCreateSearch"
:toolbarSettings="toolbarSettings">
</ejs-pdfviewer>
</div>
</template>
<script>
import {
PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation,
BookmarkView, ThumbnailView, Print, TextSelection, TextSearch,
Annotation, FormDesigner, FormFields
} from '@syncfusion/ej2-vue-pdfviewer';
import { ComboBox } from "@syncfusion/ej2-dropdowns";
import { TextBox } from "@syncfusion/ej2-inputs";
export default {
name: "App",
components: {
"ejs-pdfviewer": PdfViewerComponent
},
data() {
// Move the toolItem declaration inside the data function
let toolItem1 = {
prefixIcon: 'e-icons e-paste',
id: 'print',
tooltipText: 'Custom toolbar item',
align: 'left'
};
let toolItem2 = {
id: 'download',
text: 'Save',
tooltipText: 'Custom toolbar item',
align: 'right'
};
let LanguageList = ['Typescript', 'Javascript', 'Angular', 'C#', 'C', 'Python'];
let toolItem3 = {
type: 'Input',
tooltipText: 'Language List',
cssClass: 'percentage',
align: 'Left',
id: 'dropdown',
template: new ComboBox({ width: 100, value: 'TypeScript', dataSource: LanguageList, popupWidth: 85, showClearButton: false, readonly: false })
};
let toolItem4 = {
type: 'Input',
tooltipText: 'Text',
align: 'Right',
cssClass: 'find',
id: 'textbox',
template: new TextBox({ width: 125, placeholder: 'Type Here' })
}
return {
documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf",
serviceUrl: "https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer",
toolbarSettings: {
toolbarItems: [toolItem1, toolItem2, 'OpenOption', 'PageNavigationTool', 'MagnificationTool', toolItem3, 'PanTool', 'SelectionTool', 'SearchOption', 'PrintOption', 'DownloadOption', 'UndoRedoTool', 'AnnotationEditTool', 'FormDesignerEditTool', toolItem4, 'CommentTool', 'SubmitForm']
}
};
},
provide: {
PdfViewer: [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView,
Print, TextSelection, TextSearch, Annotation, FormDesigner, FormFields]
},
methods: {
toolbarClick: function (args) {
if (args.item && args.item.id === 'print') {
this.$refs.pdfviewer.ej2Instances.printModule.print();
}
else if (args.item && args.item.id === 'download') {
this.$refs.pdfviewer.ej2Instances.download();
}
},
}
}
</script>Note : Default value of toolbar items is [‘OpenOption’, ‘PageNavigationTool’,’MagnificationTool’, ‘PanTool’, ‘SelectionTool’, ‘SearchOption’, ‘PrintOption’, ‘DownloadOption’,’UndoRedoTool’, ‘AnnotationEditTool’, ‘FormDesignerEditTool’, ‘CommentTool’, ‘SubmitForm’]
Align Property
The align property is used to specify the alignment of a toolbar item 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
The tooltip property is used to set the tooltip text for a toolbar item. Tooltip provides additional information when a user hovers over the item.
CssClass Property
The cssClass property is used to apply custom CSS classes to a toolbar item. It allows custom styling of the toolbar item.
Prefix Property
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.
ID Property
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.
When defining or customizing toolbar items, it is mandatory to assign a specific and descriptive id to each item.
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.
NOTE
When customizing toolbar items, you have the flexibility to include either icons or text based on your design preference.
Custom Toolbar
The PDF Viewer provides API for user interactions options provided in it’s built-in toolbar. Using this we can create our own User Interface for toolbar actions in application level by hiding the built-in toolbar. The following steps are used to create the custom toolbar for PDF Viewer,
Step 1: Follow the steps provided in the link to create simple PDF Viewer sample.
Step 2: Now, add an HTML div element in template to act as the custom toolbar PDF Viewer using the following code.
<template>
<div>
<ejs-toolbar id="customToolbar" ref="toolbar">
<e-items>
<e-item prefixIcon='e-pv-open-document-icon' tooltipText='Open' :click="openClicked"></e-item>
<e-item prefixIcon='e-pv-previous-page-navigation-icon' id="previousPage" tooltipText='Previous Page' align='Center' :click="previousClicked"></e-item>
<e-item prefixIcon='e-pv-next-page-navigation-icon' id="nextPage" tooltipText='Next Page' align='Center' :click="nextClicked"></e-item>
<e-item :template='pageNoTemplate' tooltipText='Page Number' align='Center'></e-item>
<e-item :template='pageTextTemplate' tooltipText='Page Number' align='Center'></e-item>
<e-item prefixIcon='e-pv-print-document-icon' tooltipText='Print' align='Right' :click="printClicked"></e-item>
<e-item prefixIcon='e-pv-download-document-icon' tooltipText='Download' align='Right' :click="downloadClicked"></e-item>
</e-items>
</ejs-toolbar>
<ejs-toolbar id="magnificationToolbar">
<e-items>
<e-item prefixIcon='e-pv-fit-page-icon' id="fitPage" tooltipText='Fit to page' :click="pageFitClicked"></e-item>
<e-item prefixIcon='e-pv-zoom-in-icon' id="zoomIn" tooltipText='Zoom in' :click="zoomInClicked"></e-item>
<e-item prefixIcon='e-pv-zoom-out-icon' id="zoomOut" tooltipText='Zoom out' :click="zoomOutClicked"></e-item>
</e-items>
</ejs-toolbar>
<input type ="file" id="fileUpload" accept=".pdf" style="display:block;visibility:hidden;width:0;height:0;"></input>
<div class="control-section">
<ejs-pdfviewer
id="pdfviewer"
ref="pdfviewer"
:pageChange="pageChange"
:documentLoad="documentLoad"
:serviceUrl="serviceUrl"
:documentPath="documentPath"
:enableToolbar="enableToolbar">
</ejs-pdfviewer>
</div>
</div>
</template><template>
<div>
<ejs-toolbar id="customToolbar" ref="toolbar">
<e-items>
<e-item prefixIcon='e-pv-open-document-icon' tooltipText='Open' :click="openClicked"></e-item>
<e-item prefixIcon='e-pv-previous-page-navigation-icon' id="previousPage" tooltipText='Previous Page' align='Center' :click="previousClicked"></e-item>
<e-item prefixIcon='e-pv-next-page-navigation-icon' id="nextPage" tooltipText='Next Page' align='Center' :click="nextClicked"></e-item>
<e-item :template='pageNoTemplate' tooltipText='Page Number' align='Center'></e-item>
<e-item :template='pageTextTemplate' tooltipText='Page Number' align='Center'></e-item>
<e-item prefixIcon='e-pv-print-document-icon' tooltipText='Print' align='Right' :click="printClicked"></e-item>
<e-item prefixIcon='e-pv-download-document-icon' tooltipText='Download' align='Right' :click="downloadClicked"></e-item>
</e-items>
</ejs-toolbar>
<ejs-toolbar id="magnificationToolbar">
<e-items>
<e-item prefixIcon='e-pv-fit-page-icon' id="fitPage" tooltipText='Fit to page' :click="pageFitClicked"></e-item>
<e-item prefixIcon='e-pv-zoom-in-icon' id="zoomIn" tooltipText='Zoom in' :click="zoomInClicked"></e-item>
<e-item prefixIcon='e-pv-zoom-out-icon' id="zoomOut" tooltipText='Zoom out' :click="zoomOutClicked"></e-item>
</e-items>
</ejs-toolbar>
<input type ="file" id="fileUpload" accept=".pdf" style="display:block;visibility:hidden;width:0;height:0;"></input>
<div class="control-section">
<ejs-pdfviewer
id="pdfviewer"
ref="pdfviewer"
:pageChange="pageChange"
:documentLoad="documentLoad"
:documentPath="documentPath"
:enableToolbar="enableToolbar">
</ejs-pdfviewer>
</div>
</div>
</template>Step 3: Import and inject the modules used for the custom toolbar,
import Vue from "vue";
import { PdfViewerPlugin, Toolbar, Magnification, Navigation,
LinkAnnotation, BookmarkView, Annotation, ThumbnailView,
Print, TextSelection, TextSearch, FormFields, FormDesigner } from "@syncfusion/ej2-vue-pdfviewer";
import { ToolbarPlugin } from "@syncfusion/ej2-vue-navigations";
import { CalendarPlugin } from '@syncfusion/ej2-vue-calendars';
Vue.use(CalendarPlugin);
Vue.use(PdfViewerPlugin);
Vue.use(ToolbarPlugin);Step 4: Hide the built-in toolbar of PDF Viewer using below code snippet,
export default Vue.extend({
data: function () {
return {
documentPath: "https://cdn.syncfusion.com/content/pdf/hive-succinctly.pdf",
enableToolbar: false,
pageNoTemplate: '<div class=""><input type="text" class="e-input-group e-pv-current-page-number" id="currentPage" /></div>',
pageTextTemplate: '<div class=""><span class="e-pv-total-page-number" id="totalPage">of 0</span></div>'
}
})
};export default Vue.extend({
data: function () {
return {
serviceUrl: "https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer",
documentPath: "https://cdn.syncfusion.com/content/pdf/hive-succinctly.pdf",
enableToolbar: false,
pageNoTemplate: '<div class=""><input type="text" class="e-input-group e-pv-current-page-number" id="currentPage" /></div>',
pageTextTemplate: '<div class=""><span class="e-pv-total-page-number" id="totalPage">of 0</span></div>'
}
})
};Step 7: Add the following style to achieve the custom toolbar styling,
<style>
#pdfviewer {
height: 640px;
}
.control-section {
padding-top: 0px !important;
}
#magnificationToolbar {
background: transparent;
height: auto;
min-height: 56px;
width: auto;
border: none;
position: absolute;
z-index: 900;
top: calc(100% - 110px);
left: calc(100% - 120px);
transform: rotate(90deg);
}
div#magnificationToolbar.e-toolbar .e-toolbar-items {
background: transparent;
padding: 2px 3px 2px 2px;
}
#magnificationToolbar.e-toolbar .e-tbar-btn {
border-radius: 50%;
min-height: 30px;
min-width: 30px;
border: 1px solid #c8c8c8;
}
#customToolbar {
top: 0px;
z-index: 900;
}
.e-bookmark-popup {
height: 300px;
max-width: 300px;
}
.e-text-search-popup {
height: 104px;
max-width: 348px;
}
.e-custom-search-input {
width: 234px;
}
.e-text-search-popup .e-footer-content, .e-bookmark-popup .e-footer-content {
padding: 0;
height: 0;
}
.search-button, .search-button:disabled, .search-button:focus, .search-button:hover {
background: transparent;
box-shadow: none;
}
#popup .e-dlg-content {
padding-left: 0;
padding-bottom: 0;
}
.e-pv-bookmarks {
min-width: 234px;
}
.e-pv-current-page-number {
width: 46px;
height: 28px;
text-align: center;
}
.material .e-pv-current-page-number {
border-width: 1px;
}
.e-icons {
font-family: "e-icons";
font-style: normal;
font-variant: normal;
font-weight: normal;
line-height: 1;
text-transform: none;
}
.e-pv-icon::before {
font-family: 'e-icons';
}
.e-pv-open-document-icon::before {
content: '\e91c';
}
.e-pv-download-document-icon::before {
content: '\e914';
}
.e-pv-print-document-icon::before {
content: '\e917';
}
.e-pv-previous-page-navigation-icon::before {
content: '\e910';
}
.e-pv-next-page-navigation-icon::before {
content: '\e911';
}
.e-pv-zoom-out-icon::before {
content: '\e912';
}
.e-pv-zoom-in-icon::before {
content: '\e91d';
}
.e-pv-fit-page-icon::before {
content: '\e91b';
}
.e-btn-icon.e-pv-zoom-out-icon.e-icons {
transform: rotate(90deg);
}
@font-face {
font-family: "e-icons";
font-style: normal;
font-weight: normal;
src: url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAAKAIAAAwAgT1MvMj8wS0QAA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A==) format('truetype');
}
</style>
The icons are embedded in the font file used in above code snippet.
Step 8: Add the following scripts for performing user interaction in PDF Viewer in code behind
import Vue from "vue";
import { PdfViewerPlugin, Toolbar, Magnification, Navigation,
LinkAnnotation, BookmarkView, Annotation, ThumbnailView,
Print, TextSelection, TextSearch, FormFields, FormDesigner } from "@syncfusion/ej2-vue-pdfviewer";
import { ToolbarPlugin } from "@syncfusion/ej2-vue-navigations";
import { CalendarPlugin } from '@syncfusion/ej2-vue-calendars';
Vue.use(CalendarPlugin);
Vue.use(PdfViewerPlugin);
Vue.use(ToolbarPlugin);
var toolbar;
var viewer;
var fileName;
var currentPageBox;
function updatePageNavigation() {
if (viewer.currentPageNumber === 1) {
toolbar.enableItems(document.getElementById('previousPage'), false);
toolbar.enableItems(document.getElementById('nextPage'), true);
}
else if (viewer.currentPageNumber === viewer.pageCount) {
toolbar.enableItems(document.getElementById('previousPage'), true);
toolbar.enableItems(document.getElementById('nextPage'), false);
}
else {
toolbar.enableItems(document.getElementById('previousPage'), true);
toolbar.enableItems(document.getElementById('nextPage'), true);
}
}
function onCurrentPageBoxKeypress(event) {
if ((event.which < 48 || event.which > 57) && event.which !== 8 && event.which !== 13) {
event.preventDefault();
return false;
}
else {
var currentPageNumber = parseInt(currentPageBox.value);
if (event.which === 13) {
if (currentPageNumber > 0 && currentPageNumber <= viewer.pageCount) {
viewer.navigation.goToPage(currentPageNumber);
}
else {
currentPageBox.value = viewer.currentPageNumber.toString();
}
}
return true;
}
}
function onCurrentPageBoxClicked() {
currentPageBox.select();
}
function readFile(args) {
// tslint:disable-next-line
let upoadedFiles = args.target.files;
if (args.target.files[0] !== null) {
let uploadedFile = upoadedFiles[0];
fileName = uploadedFile.name;
if (uploadedFile) {
let reader = new FileReader();
reader.readAsDataURL(uploadedFile);
// tslint:disable-next-line
reader.onload = function (e) {
let uploadedFileUrl = e.currentTarget.result;
viewer.load(uploadedFileUrl, null);
viewer.fileName = fileName;
};
}
}
};
export default Vue.extend({
data: function () {
return {
documentPath: "https://cdn.syncfusion.com/content/pdf/hive-succinctly.pdf",
enableToolbar: false,
pageNoTemplate: '<div class=""><input type="text" class="e-input-group e-pv-current-page-number" id="currentPage" /></div>',
pageTextTemplate: '<div class=""><span class="e-pv-total-page-number" id="totalPage">of 0</span></div>'
}
},
PdfViewer: [ Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, Annotation,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner ]},
methods: {
openClicked: function (args) {
document.getElementById('fileUpload').click();
},
previousClicked: function (args) {
viewer.navigation.goToPreviousPage();
},
nextClicked: function (args) {
viewer.navigation.goToNextPage();
},
printClicked: function (args) {
viewer.print.print();
},
downloadClicked: function (args) {
viewer.download();
},
pageFitClicked: function (args) {
viewer.magnification.fitToPage();
},
zoomInClicked: function (args) {
viewer.magnification.zoomIn();
},
zoomOutClicked: function (args) {
viewer.magnification.zoomOut();
},
pageChange: function (args) {
currentPageBox = document.getElementById('currentPage');
currentPageBox.value = viewer.currentPageNumber.toString();
updatePageNavigation();
},
documentLoad: function (args) {
viewer = this.$refs.pdfviewer.ej2Instances;
toolbar = this.$refs.toolbar.ej2Instances;
currentPageBox = document.getElementById('currentPage');
currentPageBox.value = '1';
document.getElementById('totalPage').textContent = 'of ' + viewer.pageCount;
currentPageBox.addEventListener('keypress', onCurrentPageBoxKeypress);
currentPageBox.addEventListener('click', onCurrentPageBoxClicked);
document.getElementById('fileUpload').addEventListener('change', readFile, false);
updatePageNavigation();
}
}
});import Vue from "vue";
import { PdfViewerPlugin, Toolbar, Magnification, Navigation,
LinkAnnotation, BookmarkView, Annotation, ThumbnailView,
Print, TextSelection, TextSearch, FormFields, FormDesigner } from "@syncfusion/ej2-vue-pdfviewer";
import { ToolbarPlugin } from "@syncfusion/ej2-vue-navigations";
import { CalendarPlugin } from '@syncfusion/ej2-vue-calendars';
Vue.use(CalendarPlugin);
Vue.use(PdfViewerPlugin);
Vue.use(ToolbarPlugin);
var toolbar;
var viewer;
var fileName;
var currentPageBox;
function updatePageNavigation() {
if (viewer.currentPageNumber === 1) {
toolbar.enableItems(document.getElementById('previousPage'), false);
toolbar.enableItems(document.getElementById('nextPage'), true);
}
else if (viewer.currentPageNumber === viewer.pageCount) {
toolbar.enableItems(document.getElementById('previousPage'), true);
toolbar.enableItems(document.getElementById('nextPage'), false);
}
else {
toolbar.enableItems(document.getElementById('previousPage'), true);
toolbar.enableItems(document.getElementById('nextPage'), true);
}
}
function onCurrentPageBoxKeypress(event) {
if ((event.which < 48 || event.which > 57) && event.which !== 8 && event.which !== 13) {
event.preventDefault();
return false;
}
else {
var currentPageNumber = parseInt(currentPageBox.value);
if (event.which === 13) {
if (currentPageNumber > 0 && currentPageNumber <= viewer.pageCount) {
viewer.navigation.goToPage(currentPageNumber);
}
else {
currentPageBox.value = viewer.currentPageNumber.toString();
}
}
return true;
}
}
function onCurrentPageBoxClicked() {
currentPageBox.select();
}
function readFile(args) {
// tslint:disable-next-line
let upoadedFiles = args.target.files;
if (args.target.files[0] !== null) {
let uploadedFile = upoadedFiles[0];
fileName = uploadedFile.name;
if (uploadedFile) {
let reader = new FileReader();
reader.readAsDataURL(uploadedFile);
// tslint:disable-next-line
reader.onload = function (e) {
let uploadedFileUrl = e.currentTarget.result;
viewer.load(uploadedFileUrl, null);
viewer.fileName = fileName;
};
}
}
};
export default Vue.extend({
data: function () {
return {
serviceUrl: "https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer",
documentPath: "https://cdn.syncfusion.com/content/pdf/hive-succinctly.pdf",
enableToolbar: false,
pageNoTemplate: '<div class=""><input type="text" class="e-input-group e-pv-current-page-number" id="currentPage" /></div>',
pageTextTemplate: '<div class=""><span class="e-pv-total-page-number" id="totalPage">of 0</span></div>'
}
},
PdfViewer: [ Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, Annotation,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner ]},
methods: {
openClicked: function (args) {
document.getElementById('fileUpload').click();
},
previousClicked: function (args) {
viewer.navigation.goToPreviousPage();
},
nextClicked: function (args) {
viewer.navigation.goToNextPage();
},
printClicked: function (args) {
viewer.print.print();
},
downloadClicked: function (args) {
viewer.download();
},
pageFitClicked: function (args) {
viewer.magnification.fitToPage();
},
zoomInClicked: function (args) {
viewer.magnification.zoomIn();
},
zoomOutClicked: function (args) {
viewer.magnification.zoomOut();
},
pageChange: function (args) {
currentPageBox = document.getElementById('currentPage');
currentPageBox.value = viewer.currentPageNumber.toString();
updatePageNavigation();
},
documentLoad: function (args) {
viewer = this.$refs.pdfviewer.ej2Instances;
toolbar = this.$refs.toolbar.ej2Instances;
currentPageBox = document.getElementById('currentPage');
currentPageBox.value = '1';
document.getElementById('totalPage').textContent = 'of ' + viewer.pageCount;
currentPageBox.addEventListener('keypress', onCurrentPageBoxKeypress);
currentPageBox.addEventListener('click', onCurrentPageBoxClicked);
document.getElementById('fileUpload').addEventListener('change', readFile, false);
updatePageNavigation();
}
}
});Sample :
https://document.syncfusion.com/demos/pdf-viewer/vue/#/tailwind3/pdfviewer/custom-toolbar.html