How can I help you?
Built-in toolbar in Angular PDF Viewer component
13 Feb 202624 minutes to read
The PDF Viewer includes a built-in toolbar that provides common actions such as page navigation, text search, view modes, download, print, bookmarks, and thumbnails.
The following table lists built-in toolbar items and their actions:
| Option | Description |
|---|---|
| OpenOption | Loads a PDF document into the PDF Viewer. |
| PageNavigationTool | Controls page navigation (GoToFirstPage, GoToLastPage, GoToPage, GoToNext, GoToPrevious). |
| MagnificationTool | Controls zooming (ZoomIn, ZoomOut, Zoom, FitPage, FitWidth). |
| PanTool | Enables page panning. |
| SelectionTool | Toggles text selection. |
| SearchOption | Enables text search within the document. |
| PrintOption | Prints the loaded PDF document. |
| DownloadOption | Downloads the loaded PDF document. |
| UndoRedoTool | Provides undo and redo for annotations. |
| AnnotationEditTool | Toggles annotation edit mode. |
| CommentTool | Adds sticky notes (comments) to pages. |
Show or hide the built-in toolbar
The PDF Viewer can show or hide the entire built-in toolbar. Two common approaches are shown below.
- Show or hide the toolbar using the
enableToolbarAPI
import { Component, OnInit } from '@angular/core';
import { LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
TextSearchService, AnnotationService, TextSelectionService,
PrintService
} from '@syncfusion/ej2-angular-pdfviewer';
@Component({
selector: 'app-container',
// specifies the template string for the PDF Viewer component
template: `<div class="content-wrapper">
<ejs-pdfviewer id="pdfViewer"
[documentPath]='document'
[toolbarSettings]='toolbarSettings'
style="height:640px;display:block">
</ejs-pdfviewer>
</div>`,
providers: [ LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
AnnotationService, TextSearchService, TextSelectionService,
PrintService]
})
export class AppComponent implements OnInit {
public document = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
}import { Component, OnInit } from '@angular/core';
import { LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
TextSearchService, AnnotationService, TextSelectionService,
PrintService
} from '@syncfusion/ej2-angular-pdfviewer';
@Component({
selector: 'app-container',
// specifies the template string for the PDF Viewer component
template: `<div class="content-wrapper">
<ejs-pdfviewer id="pdfViewer"
[serviceUrl]='service'
[documentPath]='document'
[toolbarSettings]='toolbarSettings'
style="height:640px;display:block">
</ejs-pdfviewer>
</div>`,
providers: [ LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
AnnotationService, TextSearchService, TextSelectionService,
PrintService]
})
export class AppComponent implements OnInit {
public service = 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer';
public document = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
}- Show or hide the toolbar at runtime with the
showToolbarmethod
<script>
window.onload = function () {
var pdfViewer = document.getElementById('pdfviewer').ej2_instances[0];
pdfViewer.toolbar.showToolbar(false);
}
</script>Show or hide toolbar items
The PDF Viewer can show or hide grouped items inside the built-in toolbar.
- Show or hide toolbar items using the
toolbarSettingsproperty
import { Component, OnInit } from '@angular/core';
import { LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService,NavigationService,
TextSearchService, AnnotationService, TextSelectionService,
PrintService
} from '@syncfusion/ej2-angular-pdfviewer';
@Component({
selector: 'app-container',
// specifies the template string for the PDF Viewer component
template:`<div class="content-wrapper">
<ejs-pdfviewer id="pdfViewer"
[documentPath]='document'
[toolbarSettings]='toolbarSettings'
style="height:640px;display:block">
</ejs-pdfviewer>
</div>`,
providers: [ LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
TextSearchService, AnnotationService, TextSelectionService,
PrintService]
})
export class AppComponent implements OnInit {
public document = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
public toolbarSettings = { showTooltip: true, toolbarItems: 'DownloadOption' }
}import { Component, OnInit } from '@angular/core';
import { LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService,NavigationService,
TextSearchService, AnnotationService, TextSelectionService,
PrintService
} from '@syncfusion/ej2-angular-pdfviewer';
@Component({
selector: 'app-container',
// specifies the template string for the PDF Viewer component
template:`<div class="content-wrapper">
<ejs-pdfviewer id="pdfViewer"
[serviceUrl]='service'
[documentPath]='document'
[toolbarSettings]='toolbarSettings'
style="height:640px;display:block">
</ejs-pdfviewer>
</div>`,
providers: [ LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
TextSearchService, AnnotationService, TextSelectionService,
PrintService]
})
export class AppComponent implements OnInit {
public service = 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer';
public document = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
public toolbarSettings = { showTooltip: true, toolbarItems: 'DownloadOption' }
}- Show or hide a specific toolbar item using
showToolbarItem
<script>
window.onload = function () {
var pdfViewer = document.getElementById('pdfviewer').ej2_instances[0];
pdfViewer.toolbar.showToolbarItem(new Array("DownloadOption"), true);
}
</script>Show/Hide the left toolbar with the thumbnails and bookmarks
The PDF Viewer can show or hide the left navigation toolbar (thumbnails and bookmarks) using the enableNavigationToolbar API. Examples follow.
import { Component, OnInit } from '@angular/core';
import { LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
TextSearchService, AnnotationService, TextSelectionService,
PrintService
} from '@syncfusion/ej2-angular-pdfviewer';
@Component({
selector: 'app-container',
// specifies the template string for the PDF Viewer component
template: `<div class="content-wrapper">
<ejs-pdfviewer id="pdfViewer"
[enableNavigationToolbar]="false"
[toolbarSettings]="toolbarSettings"
[documentPath]='document'
style="height:640px;display:block">
</ejs-pdfviewer>
</div>`,
providers: [ LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
AnnotationService, TextSearchService, TextSelectionService,
PrintService]
})
export class AppComponent implements OnInit {
public document = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
public toolbarSettings = { showTooltip: true, toolbarItems: ['OpenOption'] };
}import { Component, OnInit } from '@angular/core';
import { LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
TextSearchService, AnnotationService, TextSelectionService,
PrintService
} from '@syncfusion/ej2-angular-pdfviewer';
@Component({
selector: 'app-container',
// specifies the template string for the PDF Viewer component
template: `<div class="content-wrapper">
<ejs-pdfviewer id="pdfViewer"
[serviceUrl]='service'
[enableNavigationToolbar]="false"
[toolbarSettings]="toolbarSettings"
[documentPath]='document'
style="height:640px;display:block">
</ejs-pdfviewer>
</div>`,
providers: [ LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
AnnotationService, TextSearchService, TextSelectionService,
PrintService]
})
export class AppComponent implements OnInit {
public service = 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer';
public document = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
public toolbarSettings = { showTooltip: true, toolbarItems: ['OpenOption'] };
}Customize the built-in toolbar
The PDF Viewer supports customizing toolbar items: add, show, hide, enable, and disable.
- Add: Define new items using the CustomToolbarItemModel and include them in the ToolbarSettings property. Handle item clicks with the toolbarclick event.
- Show / Hide: Show or hide predefined items through
ToolbarSettings. See the ToolbarItem API for available identifiers. - Enable / Disable: Enable or disable toolbar items using the enabletoolbaritem API.
import { Component, OnInit } from '@angular/core';
import {
LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
AnnotationService, TextSearchService, TextSelectionService,
PrintService, FormDesignerService, FormFieldsService, CustomToolbarItemModel
} from '@syncfusion/ej2-angular-pdfviewer';
import { ComboBox } from "@syncfusion/ej2-dropdowns";
import { TextBox } from "@syncfusion/ej2-inputs";
import { ClickEventArgs } from '@syncfusion/ej2-angular-navigations';
@Component({
selector: 'app-root',
template: `<div class="content-wrapper">
<ejs-pdfviewer id="pdfViewer"
[documentPath]="document"
[resourceUrl]="resource"
[toolbarSettings]="toolbarSettings"
(toolbarClick)="toolbarClick($event)"
style="height:640px;display:block">
</ejs-pdfviewer>
</div>`,
providers: [LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
AnnotationService, TextSearchService, TextSelectionService,
PrintService, FormDesignerService, FormFieldsService]
})
export class AppComponent implements OnInit {
public document = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
public resource = 'https://cdn.syncfusion.com/ej2/24.1.41/dist/ej2-pdfviewer-lib';
public toolItem1: CustomToolbarItemModel = {
prefixIcon: 'e-icons e-paste',
id: 'print',
tooltipText: 'Custom toolbar item',
};
public toolItem2: CustomToolbarItemModel = {
id: 'download',
text: 'Save',
tooltipText: 'Custom toolbar item',
align: 'right'
};
LanguageList: string[] = ['Typescript', 'Javascript', 'Angular', 'C#', 'C', 'Python'];
public toolItem3: CustomToolbarItemModel = {
type: 'Input',
tooltipText: 'Language List',
cssClass: 'percentage',
align: 'Left',
id: 'dropdown',
template: new ComboBox({ width: 100, value: 'TypeScript', dataSource: this.LanguageList, popupWidth: 85, showClearButton: false, readonly: false })
};
public toolItem4: CustomToolbarItemModel = {
type: 'Input',
tooltipText: 'Text',
align: 'Right',
cssClass: 'find',
id: 'textbox',
template: new TextBox({ width: 125, placeholder: 'Type Here', created: this.OnCreateSearch})
}
public toolbarSettings = {
showTooltip: true,
toolbarItems: [this.toolItem1, this.toolItem2, 'OpenOption', 'PageNavigationTool', 'MagnificationTool', this.toolItem3, 'PanTool', 'SelectionTool', 'SearchOption', 'PrintOption', 'DownloadOption', 'UndoRedoTool', 'AnnotationEditTool', 'FormDesignerEditTool', this.toolItem4, 'CommentTool', 'SubmitForm']
};
public toolbarClick(args: ClickEventArgs): void {
var pdfViewer = (<any>document.getElementById('pdfViewer')).ej2_instances[0];
if (args.item && args.item.id === 'print') {
pdfViewer.printModule.print();
} else if (args.item && args.item.id === 'download') {
pdfViewer.download();
}
}
public OnCreateSearch(this: any): any {
this.addIcon('prepend', 'e-icons e-search');
}
ngOnInit(): void {
}
}import { Component, OnInit } from '@angular/core';
import {
LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
AnnotationService, TextSearchService, TextSelectionService,
PrintService, FormDesignerService, FormFieldsService, CustomToolbarItemModel
} from '@syncfusion/ej2-angular-pdfviewer';
import { ComboBox } from "@syncfusion/ej2-dropdowns";
import { TextBox } from "@syncfusion/ej2-inputs";
import { ClickEventArgs } from '@syncfusion/ej2-angular-navigations';
@Component({
selector: 'app-root',
template: `<div class="content-wrapper">
<ejs-pdfviewer id="pdfViewer"
[documentPath]="document"
[serviceUrl]="service"
[toolbarSettings]="toolbarSettings"
(toolbarClick)="toolbarClick($event)"
style="height:640px;display:block">
</ejs-pdfviewer>
</div>`,
providers: [LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
AnnotationService, TextSearchService, TextSelectionService,
PrintService, FormDesignerService, FormFieldsService]
})
export class AppComponent implements OnInit {
public document = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
public service = 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer';
public toolItem1: CustomToolbarItemModel = {
prefixIcon: 'e-icons e-paste',
id: 'print',
tooltipText: 'Custom toolbar item',
};
public toolItem2: CustomToolbarItemModel = {
id: 'download',
text: 'Save',
tooltipText: 'Custom toolbar item',
align: 'right'
};
LanguageList: string[] = ['Typescript', 'Javascript', 'Angular', 'C#', 'C', 'Python'];
public toolItem3: CustomToolbarItemModel = {
type: 'Input',
tooltipText: 'Language List',
cssClass: 'percentage',
align: 'Left',
id: 'dropdown',
template: new ComboBox({ width: 100, value: 'TypeScript', dataSource: this.LanguageList, popupWidth: 85, showClearButton: false, readonly: false })
};
public toolItem4: CustomToolbarItemModel = {
type: 'Input',
tooltipText: 'Text',
align: 'Right',
cssClass: 'find',
id: 'textbox',
template: new TextBox({ width: 125, placeholder: 'Type Here', created: this.OnCreateSearch})
}
public toolbarSettings = {
showTooltip: true,
toolbarItems: [this.toolItem1, this.toolItem2, 'OpenOption', 'PageNavigationTool', 'MagnificationTool', this.toolItem3, 'PanTool', 'SelectionTool', 'SearchOption', 'PrintOption', 'DownloadOption', 'UndoRedoTool', 'AnnotationEditTool', 'FormDesignerEditTool', this.toolItem4, 'CommentTool', 'SubmitForm']
};
public toolbarClick(args: ClickEventArgs): void {
var pdfViewer = (<any>document.getElementById('pdfViewer')).ej2_instances[0];
if (args.item && args.item.id === 'print') {
pdfViewer.printModule.print();
} else if (args.item && args.item.id === 'download') {
pdfViewer.download();
}
}
public OnCreateSearch(this: any): any {
this.addIcon('prepend', 'e-icons e-search');
}
ngOnInit(): void {
}
}NOTE
Default toolbar items are
['OpenOption', 'PageNavigationTool', 'MagnificationTool', 'PanTool', 'SelectionTool', 'SearchOption', 'PrintOption', 'DownloadOption', 'UndoRedoTool', 'AnnotationEditTool', 'FormDesignerEditTool', 'CommentTool', 'SubmitForm'].
Align property
The align property specifies a toolbar item’s horizontal alignment.
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 tooltipText property sets the tooltip shown on hover for a toolbar item.
CssClass Property
The cssClass property applies custom CSS classes to a toolbar item for custom styling.
Prefix Property
The prefixIcon property sets an icon CSS class to display before the toolbar item’s content.
ID Property
The id property of a CustomToolbarItemModel is required and provides a unique identifier for each toolbar item. Use descriptive id values so handlers and API calls can reference items reliably.
These properties are used when defining custom toolbar items for the Syncfusion® PDF Viewer. Include them in ToolbarSettings to adjust appearance and behavior.
NOTE
Custom toolbar items may display either icons or text depending on the design preference.
Custom toolbar
The PDF Viewer exposes APIs so applications can implement a custom toolbar UI. Hide the built-in toolbar and wire an application-level toolbar to the viewer using these APIs. The following steps demonstrate the approach.
Step 1: Follow the getting-started guide to create a simple PDF Viewer sample.
Step 2: Hide the built-in toolbar using the enableToolbar and enableNavigationToolbar flags. Example code follows.
<ejs-pdfviewer #pdfviewer id='pdfViewer'
[documentPath]='document'
[enableToolbar]=false
[enableNavigationToolbar]=false
(pageChange)='pageChanged($event)'
(documentLoad)='documentLoaded($event)'
style="height:640px; display: block">
</ejs-pdfviewer><ejs-pdfviewer #pdfviewer id='pdfViewer'
[serviceUrl]='service'
[documentPath]='document'
[enableToolbar]=false
[enableNavigationToolbar]=false
(pageChange)='pageChanged($event)'
(documentLoad)='documentLoaded($event)'
style="height:640px; display: block">
</ejs-pdfviewer>Step 3: Add an EJ2 toolbar for primary actions (Open, Previous, Next, Go to page, Print, Download). Example code follows.
<ejs-toolbar id='topToolbar' #customToolbar>
<e-items>
<e-item prefixIcon='e-pv-open-document-icon' id='openDocument' tooltipText='Open' (click)='openDocument($event)'>
</e-item>
<e-item prefixIcon='e-pv-previous-page-navigation-icon' id='previousPage' tooltipText='Previous Page' (click)='previousClicked($event)'
align='Center'></e-item>
<e-item prefixIcon='e-pv-next-page-navigation-icon' id='nextPage' tooltipText='Next Page' (click)='nextClicked($event)' align='Center'></e-item>
<e-item align='Center'>
<ng-template #template>
<div class=''>
<input type='text' class='e-input-group e-pv-current-page-number' id='currentPage' value="0"
(keypress)='onCurrentPageBoxKeypress($event)' (click)='onCurrentPageBoxClicked($event)' />
</div>
<div style='margin-left: 6px'><span class='e-pv-total-page-number' id='totalPage'>of 0</span></div>
</ng-template>
</e-item>
<e-item prefixIcon='e-pv-print-document-icon' tooltipText='Print' (click)='printClicked($event)' align='Right'></e-item>
<e-item prefixIcon='e-pv-download-document-icon' tooltipText='Download' (click)='downloadClicked($event)' align='Right'></e-item>
</e-items>
</ejs-toolbar>
<input type="file" id="fileUpload" accept=".pdf" style="display:block;visibility:hidden;width:0;height:0;">Step 4: Add an EJ2 toolbar for magnification actions (Fit to page, Zoom in, Zoom out). Example code follows.
<ejs-toolbar id='magnificationToolbar' #zoomToolbar>
<e-items>
<e-item prefixIcon='e-pv-fit-page-icon' id='fitPage' tooltipText='Fit to page' (click)='pageFitClicked($event)'></e-item>
<e-item prefixIcon='e-pv-zoom-in-icon' id='zoomIn' tooltipText='Zoom in' (click)='zoomInClicked($event)'></e-item>
<e-item prefixIcon='e-pv-zoom-out-sample' id='zoomOut' tooltipText='Zoom out' (click)='zoomOutClicked($event)'></e-item>
</e-items>
</ejs-toolbar>Step 5: Add the following CSS to style the custom toolbar.
#magnificationToolbar {
background: transparent;
height: auto;
min-height: 56px;
width: 200px;
border: none;
position: absolute;
z-index: 1001;
bottom: 58px;
right: 16px;
transform: rotate(90deg);
}
#magnificationToolbar.e-toolbar .e-toolbar-items {
background: transparent;
}
#magnificationToolbar.e-toolbar .e-tbar-btn {
border-radius: 50%;
min-height: 30px;
min-width: 30px;
border: 1px solid #c8c8c8;
}
#topToolbar {
top: 0px;
z-index: 1001;
}
.e-tbar-section .e-sample-resize-container {
height: 46px;
}
.e-bookmark-popup {
height: 200px;
max-width: 250px;
}
.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-icon-search::before {
font-family: 'e-icons';
font-size: 12px;
}
.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-sample::before {
content: '\e912';
}
.e-pv-zoom-out-sample {
transform: rotate(90deg);
padding-right: 2px;
}
.e-pv-zoom-in-icon::before {
content: '\e91d';
}
.e-pv-fit-page-icon::before {
content: '\e91b';
}
.e-pv-open-document-icon::before {
content: '\e91c';
}
@font-face {
font-family: "e-icons";
font-style: normal;
font-weight: normal;
src: url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAAKAIAAAwAgT1MvMj8wS0QAAAEoAAAAVmNtYXDSeNLMAAABuAAAAFZnbHlmok0NtwAAAjAAAAPkaGVhZBN3pEcAAADQAAAANmhoZWEHrwNhAAAArAAAACRobXR4NsgAAAAAAYAAAAA4bG9jYQdkBmQAAAIQAAAAHm1heHABHAAwAAABCAAAACBuYW1lD0oZXgAABhQAAALBcG9zdFG4mE4AAAjYAAAAyAABAAADUv9qAFoEAAAA/+gEAAABAAAAAAAAAAAAAAAAAAAADgABAAAAAQAAxsly1F8PPPUACwPoAAAAANgsr7EAAAAA2CyvsQAAAAAEAAQAAAAACAACAAAAAAAAAAEAAAAOACQABAAAAAAAAgAAAAoACgAAAP8AAAAAAAAAAQPqAZAABQAAAnoCvAAAAIwCegK8AAAB4AAxAQIAAAIABQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUGZFZABA6RDpHQNS/2oAWgQAAJYAAAABAAAAAAAABAAAAAPoAAAD6AAAA+gAAAPoAAAD6AAAA+gAAAPoAAAD6AAAA+gAAAPoAAAD6AAAA+gAAAPoAAAAAAACAAAAAwAAABQAAwABAAAAFAAEAEIAAAAGAAQAAQAC6RLpHf//AADpEOkU//8AAAAAAAEABgAKAAAAAQACAAMABQAGAAcACAAJAAoACwAMAA0ABAAAAAAAAAAUACoAZACkAL4A7gEuAVwBcAGEAZ4ByAHyAAAAAQAAAAAD6gMuAAUAAAkBBwkBJwIAAet0/on+iXQDL/4VcwF3/olzAAEAAAAAA+oDLgAFAAATCQEXCQGJAXcBd3T+Ff4VAy/+iQF3c/4VAesAAAAAAwAAAAAEAAQAAAMADwAbAAABITUhBQ4BBy4BJz4BNx4BBRYAFzYANyYAJwYAAQACAP4AAoAE2aOj2QQE2aOj2fyEBgEh2dkBIQYG/t/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FZfWm9vbW91dAlQVl9ab29taW4LUFZfRG93bmxvYWQLUFZfQm9va21hcmsJUFZfU2VhcmNoCFBWX1ByaW50C1BWX1ByZXZpb3VzB1BWX05leHQIUFZfQ2xvc2UMUFZfRml0VG9QYWdlB1BWX09wZW4AAA==) format('truetype');
}NOTE
The icons are embedded in the font file used in the previous snippet.
Step 5: Add the following code snippet in app.ts file for performing a user interaction in PDF Viewer in code behind.
@ViewChild('pdfviewer')
public pdfviewerControl: PdfViewerComponent;
@ViewChild('customToolbar')
public customToolbar: ToolbarComponent;
@ViewChild('zoomToolbar')
public zoomToolbar: ToolbarComponent;
public document: string = 'https://cdn.syncfusion.com/content/pdf/hive-succinctly.pdf';
constructor() { }
ngOnInit(): void {
// ngOnInit function
document
.getElementById('fileUpload')
.addEventListener('change', this.readFile.bind(this));
}
public openDocument(e: ClickEventArgs): void {
document.getElementById('fileUpload').click();
}
public previousClicked(e: ClickEventArgs): void {
this.pdfviewerControl.navigation.goToPreviousPage();
}
public nextClicked(e: ClickEventArgs): void {
this.pdfviewerControl.navigation.goToNextPage();
}
public printClicked(e: ClickEventArgs): void {
this.pdfviewerControl.print.print();
}
public downloadClicked(e: ClickEventArgs): void {
let fileName: string = (document.getElementById(
'fileUpload'
) as HTMLInputElement).value
.split('\\')
.pop();
if(fileName !== '') {
this.pdfviewerControl.fileName = fileName;
}
this.pdfviewerControl.download();
}
public pageFitClicked(e: ClickEventArgs): void {
this.pdfviewerControl.magnification.fitToPage();
this.updateZoomButtons();
this.customToolbar.enableItems(document.getElementById('fitPage'), false);
}
public zoomInClicked(e: ClickEventArgs): void {
this.pdfviewerControl.magnification.zoomIn();
this.updateZoomButtons();
}
public zoomOutClicked(e: ClickEventArgs): void {
this.pdfviewerControl.magnification.zoomOut();
this.updateZoomButtons();
}
public pageChanged(e: PageChangeEventArgs): void {
(document.getElementById(
'currentPage'
) as HTMLInputElement).value = this.pdfviewerControl.currentPageNumber.toString();
this.updatePageNavigation();
}
public documentLoaded(e: LoadEventArgs): void {
document.getElementById('totalPage').textContent =
'of ' + this.pdfviewerControl.pageCount;
(document.getElementById(
'currentPage'
) as HTMLInputElement).value = this.pdfviewerControl.currentPageNumber.toString();
this.updatePageNavigation();
}
public onCurrentPageBoxClicked(e: ClickEventArgs): void {
(document.getElementById('currentPage') as HTMLInputElement).select();
}
public onCurrentPageBoxKeypress(e: KeyboardEvent): boolean {
if ((e.which < 48 || e.which > 57) && e.which !== 8 && e.which !== 13) {
e.preventDefault();
return false;
} else {
// tslint:disable-next-line:radix
const currentPageNumber: number = parseInt(
(document.getElementById('currentPage') as HTMLInputElement).value
);
if (e.which === 13) {
if (
currentPageNumber > 0 &&
currentPageNumber <= this.pdfviewerControl.pageCount
) {
this.pdfviewerControl.navigation.goToPage(currentPageNumber);
} else {
// tslint:disable-next-line:max-line-length
(document.getElementById(
'currentPage'
) as HTMLInputElement).value = this.pdfviewerControl.currentPageNumber.toString();
}
}
return true;
}
}
private updatePageNavigation(): void {
if(this.pdfviewerControl.currentPageNumber === 1) {
this.customToolbar.enableItems(
document.getElementById('previousPage'),
false
);
this.customToolbar.enableItems(document.getElementById('nextPage'), true);
} else if (
this.pdfviewerControl.currentPageNumber ===
this.pdfviewerControl.pageCount
) {
this.customToolbar.enableItems(
document.getElementById('previousPage'),
true
);
this.customToolbar.enableItems(
document.getElementById('nextPage'),
false
);
} else {
this.customToolbar.enableItems(
document.getElementById('previousPage'),
true
);
this.customToolbar.enableItems(document.getElementById('nextPage'), true);
}
}
private updateZoomButtons(): void {
if(this.pdfviewerControl.zoomPercentage <= 50) {
this.zoomToolbar.enableItems(document.getElementById('zoomIn'), true);
this.zoomToolbar.enableItems(document.getElementById('zoomOut'), false);
this.zoomToolbar.enableItems(document.getElementById('fitPage'), true);
} else if (this.pdfviewerControl.zoomPercentage >= 400) {
this.zoomToolbar.enableItems(document.getElementById('zoomIn'), false);
this.zoomToolbar.enableItems(document.getElementById('zoomOut'), true);
this.zoomToolbar.enableItems(document.getElementById('fitPage'), true);
} else {
this.zoomToolbar.enableItems(document.getElementById('zoomIn'), true);
this.zoomToolbar.enableItems(document.getElementById('zoomOut'), true);
this.zoomToolbar.enableItems(document.getElementById('fitPage'), true);
}
}
// tslint:disable-next-line
private readFile(args: any): void {
// tslint:disable-next-line
let upoadedFiles: any = args.target.files;
if(args.target.files[0] !== null) {
let uploadedFile: File = upoadedFiles[0];
if (uploadedFile) {
let reader: FileReader = new FileReader();
reader.readAsDataURL(uploadedFile);
// tslint:disable-next-line
let proxy: any = this;
// tslint:disable-next-line
reader.onload = (e: any): void => {
let uploadedFileUrl: string = e.currentTarget.result;
proxy.pdfviewerControl.load(uploadedFileUrl, null);
};
}
}
}@ViewChild('pdfviewer')
public pdfviewerControl: PdfViewerComponent;
@ViewChild('customToolbar')
public customToolbar: ToolbarComponent;
@ViewChild('zoomToolbar')
public zoomToolbar: ToolbarComponent;
public service: string =
'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer';
public document: string = 'https://cdn.syncfusion.com/content/pdf/hive-succinctly.pdf';
constructor() { }
ngOnInit(): void {
// ngOnInit function
document
.getElementById('fileUpload')
.addEventListener('change', this.readFile.bind(this));
}
public openDocument(e: ClickEventArgs): void {
document.getElementById('fileUpload').click();
}
public previousClicked(e: ClickEventArgs): void {
this.pdfviewerControl.navigation.goToPreviousPage();
}
public nextClicked(e: ClickEventArgs): void {
this.pdfviewerControl.navigation.goToNextPage();
}
public printClicked(e: ClickEventArgs): void {
this.pdfviewerControl.print.print();
}
public downloadClicked(e: ClickEventArgs): void {
let fileName: string = (document.getElementById(
'fileUpload'
) as HTMLInputElement).value
.split('\\')
.pop();
if(fileName !== '') {
this.pdfviewerControl.fileName = fileName;
}
this.pdfviewerControl.download();
}
public pageFitClicked(e: ClickEventArgs): void {
this.pdfviewerControl.magnification.fitToPage();
this.updateZoomButtons();
this.customToolbar.enableItems(document.getElementById('fitPage'), false);
}
public zoomInClicked(e: ClickEventArgs): void {
this.pdfviewerControl.magnification.zoomIn();
this.updateZoomButtons();
}
public zoomOutClicked(e: ClickEventArgs): void {
this.pdfviewerControl.magnification.zoomOut();
this.updateZoomButtons();
}
public pageChanged(e: PageChangeEventArgs): void {
(document.getElementById(
'currentPage'
) as HTMLInputElement).value = this.pdfviewerControl.currentPageNumber.toString();
this.updatePageNavigation();
}
public documentLoaded(e: LoadEventArgs): void {
document.getElementById('totalPage').textContent =
'of ' + this.pdfviewerControl.pageCount;
(document.getElementById(
'currentPage'
) as HTMLInputElement).value = this.pdfviewerControl.currentPageNumber.toString();
this.updatePageNavigation();
}
public onCurrentPageBoxClicked(e: ClickEventArgs): void {
(document.getElementById('currentPage') as HTMLInputElement).select();
}
public onCurrentPageBoxKeypress(e: KeyboardEvent): boolean {
if ((e.which < 48 || e.which > 57) && e.which !== 8 && e.which !== 13) {
e.preventDefault();
return false;
} else {
// tslint:disable-next-line:radix
const currentPageNumber: number = parseInt(
(document.getElementById('currentPage') as HTMLInputElement).value
);
if (e.which === 13) {
if (
currentPageNumber > 0 &&
currentPageNumber <= this.pdfviewerControl.pageCount
) {
this.pdfviewerControl.navigation.goToPage(currentPageNumber);
} else {
// tslint:disable-next-line:max-line-length
(document.getElementById(
'currentPage'
) as HTMLInputElement).value = this.pdfviewerControl.currentPageNumber.toString();
}
}
return true;
}
}
private updatePageNavigation(): void {
if(this.pdfviewerControl.currentPageNumber === 1) {
this.customToolbar.enableItems(
document.getElementById('previousPage'),
false
);
this.customToolbar.enableItems(document.getElementById('nextPage'), true);
} else if (
this.pdfviewerControl.currentPageNumber ===
this.pdfviewerControl.pageCount
) {
this.customToolbar.enableItems(
document.getElementById('previousPage'),
true
);
this.customToolbar.enableItems(
document.getElementById('nextPage'),
false
);
} else {
this.customToolbar.enableItems(
document.getElementById('previousPage'),
true
);
this.customToolbar.enableItems(document.getElementById('nextPage'), true);
}
}
private updateZoomButtons(): void {
if(this.pdfviewerControl.zoomPercentage <= 50) {
this.zoomToolbar.enableItems(document.getElementById('zoomIn'), true);
this.zoomToolbar.enableItems(document.getElementById('zoomOut'), false);
this.zoomToolbar.enableItems(document.getElementById('fitPage'), true);
} else if (this.pdfviewerControl.zoomPercentage >= 400) {
this.zoomToolbar.enableItems(document.getElementById('zoomIn'), false);
this.zoomToolbar.enableItems(document.getElementById('zoomOut'), true);
this.zoomToolbar.enableItems(document.getElementById('fitPage'), true);
} else {
this.zoomToolbar.enableItems(document.getElementById('zoomIn'), true);
this.zoomToolbar.enableItems(document.getElementById('zoomOut'), true);
this.zoomToolbar.enableItems(document.getElementById('fitPage'), true);
}
}
// tslint:disable-next-line
private readFile(args: any): void {
// tslint:disable-next-line
let upoadedFiles: any = args.target.files;
if(args.target.files[0] !== null) {
let uploadedFile: File = upoadedFiles[0];
if (uploadedFile) {
let reader: FileReader = new FileReader();
reader.readAsDataURL(uploadedFile);
// tslint:disable-next-line
let proxy: any = this;
// tslint:disable-next-line
reader.onload = (e: any): void => {
let uploadedFileUrl: string = e.currentTarget.result;
proxy.pdfviewerControl.load(uploadedFileUrl, null);
};
}
}
}Find the sample of Toolbar Customization