|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Navigation in JavaScript Pdfviewer control | Syncfusion |
| 4 | +description: Learn here all about Navigation in Syncfusion JavaScript Pdfviewer control of Syncfusion Essential JS 2 and more. |
| 5 | +platform: document-processing |
| 6 | +control: PDF Viewer |
| 7 | +documentation: ug |
| 8 | +domainurl: ##DomainURL## |
| 9 | +--- |
| 10 | + |
| 11 | +# Navigation in JavaScript PDF Viewer control |
| 12 | + |
| 13 | +The JavaScript PDF Viewer supports different internal and external navigations. |
| 14 | + |
| 15 | +## Toolbar page navigation option |
| 16 | + |
| 17 | +The default toolbar of PDF Viewer contains the following navigation options |
| 18 | + |
| 19 | +* [**Go to page**](https://ej2.syncfusion.com/documentation/api/pdfviewer/navigation/#gotopage):- Navigates to the specific page of a PDF document. |
| 20 | +* [**Show next page**](https://ej2.syncfusion.com/documentation/api/pdfviewer/navigation/#gotonextpage):- Navigates to the next page of PDF a document. |
| 21 | +* [**Show previous page**](https://ej2.syncfusion.com/documentation/api/pdfviewer/navigation/#gotopreviouspage):- Navigates to the previous page of a PDF document. |
| 22 | +* [**Show first page**](https://ej2.syncfusion.com/documentation/api/pdfviewer/navigation/#gotofirstpage):- Navigates to the first page of a PDF document. |
| 23 | +* [**Show last page**](https://ej2.syncfusion.com/documentation/api/pdfviewer/navigation/#gotolastpage):- Navigates to the last page of a PDF document. |
| 24 | + |
| 25 | +```html |
| 26 | +<html> |
| 27 | + <head> |
| 28 | + <script src="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2.min.js" type="text/javascript"></script> |
| 29 | + <link href="https://cdn.syncfusion.com/ej2/31.2.2/tailwind3.css" rel="stylesheet" /> |
| 30 | + </head> |
| 31 | + <body> |
| 32 | + <div class="container"> |
| 33 | + <div id="pdfViewer" style="height: 640px; width: 100%"></div> |
| 34 | + </div> |
| 35 | + </body> |
| 36 | +</html> |
| 37 | +``` |
| 38 | + |
| 39 | +You can enable/disable page navigation option in PDF Viewer using the following code snippet., |
| 40 | + |
| 41 | +{% tabs %} |
| 42 | +{% highlight js tabtitle="Standalone" %} |
| 43 | + |
| 44 | +ej.pdfviewer.PdfViewer.Inject( |
| 45 | + ej.pdfviewer.Toolbar, ej.pdfviewer.Magnification, ej.pdfviewer.Navigation, |
| 46 | + ej.pdfviewer.LinkAnnotation, ej.pdfviewer.ThumbnailView, ej.pdfviewer.BookmarkView, |
| 47 | + ej.pdfviewer.TextSelection |
| 48 | +); |
| 49 | + |
| 50 | +var pdfviewer = new ej.pdfviewer.PdfViewer({ |
| 51 | + enableNavigation: true, |
| 52 | + documentPath: 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf' |
| 53 | +}); |
| 54 | + |
| 55 | +pdfviewer.appendTo('#PdfViewer'); |
| 56 | + |
| 57 | +{% endhighlight %} |
| 58 | +{% highlight js tabtitle="Server-Backed" %} |
| 59 | + |
| 60 | +var pdfviewer = new ej.pdfviewer.PdfViewer({ |
| 61 | + enableNavigation: true, |
| 62 | + documentPath: 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf' |
| 63 | +}); |
| 64 | + |
| 65 | +ej.pdfviewer.PdfViewer.Inject( |
| 66 | + ej.pdfviewer.Toolbar, ej.pdfviewer.Magnification, ej.pdfviewer.Navigation, ej.pdfviewer.LinkAnnotation, ej.pdfviewer.ThumbnailView, ej.pdfviewer.BookmarkView, ej.pdfviewer.TextSelection |
| 67 | +); |
| 68 | + |
| 69 | +pdfviewer.serviceUrl = 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/'; |
| 70 | +pdfviewer.appendTo('#PdfViewer'); |
| 71 | + |
| 72 | +{% endhighlight %} |
| 73 | +{% endtabs %} |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +Also, you can programmatically perform page navigation options as follows. |
| 78 | + |
| 79 | +```html |
| 80 | +<html> |
| 81 | + <head> |
| 82 | + <script src="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2.min.js" type="text/javascript"></script> |
| 83 | + <link href="https://cdn.syncfusion.com/ej2/31.2.2/tailwind3.css" rel="stylesheet" /> |
| 84 | + </head> |
| 85 | + <body> |
| 86 | + <div class="container"> |
| 87 | + <button id="goToFirstPage">Go To First Page</button> |
| 88 | + <button id="goToLastPage">Go To last Page</button> |
| 89 | + <button id="goToNextPage">Go To Next Page</button> |
| 90 | + <button id="goToPage">Go To Page 4</button> |
| 91 | + <button id="goToPreviousPage">Go To Previous Page</button> |
| 92 | + <div id="pdfViewer" style="height: 640px; width: 100%"></div> |
| 93 | + </div> |
| 94 | + </body> |
| 95 | +</html> |
| 96 | +``` |
| 97 | + |
| 98 | +{% tabs %} |
| 99 | +{% highlight js tabtitle="Standalone" %} |
| 100 | + |
| 101 | +var viewer = new ej.pdfviewer.PdfViewer ({ |
| 102 | + documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf", |
| 103 | + resourceUrl:'https://cdn.syncfusion.com/ej2/23.2.6/dist/ej2-pdfviewer-lib' |
| 104 | +}); |
| 105 | + |
| 106 | +ej.pdfviewer.PdfViewer.Inject(ej.pdfviewer.Toolbar, ej.pdfviewer.Magnification, ej.pdfviewer.BookmarkView, |
| 107 | + ej.pdfviewer.ThumbnailView, ej.pdfviewer.TextSelection, ej.pdfviewer.TextSearch, ej.pdfviewer.Print, |
| 108 | + ej.pdfviewer.Navigation, ej.pdfviewer.LinkAnnotation, ej.pdfviewer.Annotation, ej.pdfviewer.FormFields, |
| 109 | + ej.pdfviewer.FormDesigner,ej.pdfviewer.PageOrganizer |
| 110 | +); |
| 111 | + |
| 112 | +viewer.appendTo('#pdfViewer'); |
| 113 | + |
| 114 | +// Go To First Page |
| 115 | +document.getElementById('goToFirstPage').addEventListener('click', () => { |
| 116 | + viewer.navigation.goToFirstPage(); |
| 117 | +}); |
| 118 | +// Go To Last Page |
| 119 | +document.getElementById('goToLastPage').addEventListener('click', () => { |
| 120 | + viewer.navigation.goToLastPage(); |
| 121 | +}); |
| 122 | +// Go To Next Page |
| 123 | +document.getElementById('goToNextPage').addEventListener('click', () => { |
| 124 | + viewer.navigation.goToNextPage(); |
| 125 | +}); |
| 126 | +// Go To Page |
| 127 | +document.getElementById('goToPage').addEventListener('click', () => { |
| 128 | + viewer.navigation.goToPage(4); |
| 129 | +}); |
| 130 | +// Go To Previous Page |
| 131 | +document.getElementById('goToPreviousPage').addEventListener('click', () => { |
| 132 | + viewer.navigation.goToPreviousPage(); |
| 133 | +}); |
| 134 | + |
| 135 | +{% endhighlight %} |
| 136 | +{% highlight js tabtitle="Server-Backed" %} |
| 137 | + |
| 138 | +var viewer = new ej.pdfviewer.PdfViewer ({ |
| 139 | + documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf", |
| 140 | + resourceUrl:'https://cdn.syncfusion.com/ej2/23.2.6/dist/ej2-pdfviewer-lib' |
| 141 | +}); |
| 142 | + |
| 143 | +ej.pdfviewer.PdfViewer.Inject(ej.pdfviewer.Toolbar, ej.pdfviewer.Magnification, ej.pdfviewer.BookmarkView, |
| 144 | + ej.pdfviewer.ThumbnailView, ej.pdfviewer.TextSelection, ej.pdfviewer.TextSearch, ej.pdfviewer.Print, |
| 145 | + ej.pdfviewer.Navigation, ej.pdfviewer.LinkAnnotation, ej.pdfviewer.Annotation, ej.pdfviewer.FormFields, |
| 146 | + ej.pdfviewer.FormDesigner, ej.pdfviewer.PageOrganizer |
| 147 | +); |
| 148 | + |
| 149 | +viewer.serviceUrl = 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer'; |
| 150 | +viewer.appendTo('#pdfViewer'); |
| 151 | + |
| 152 | +// Go To First Page |
| 153 | +document.getElementById('goToFirstPage').addEventListener('click', () => { |
| 154 | +viewer.navigation.goToFirstPage(); |
| 155 | +}); |
| 156 | +// Go To Last Page |
| 157 | +document.getElementById('goToLastPage').addEventListener('click', () => { |
| 158 | +viewer.navigation.goToLastPage(); |
| 159 | +}); |
| 160 | +// Go To Next Page |
| 161 | +document.getElementById('goToNextPage').addEventListener('click', () => { |
| 162 | +viewer.navigation.goToNextPage(); |
| 163 | +}); |
| 164 | +// Go To Page |
| 165 | +document.getElementById('goToPage').addEventListener('click', () => { |
| 166 | +viewer.navigation.goToPage(4); |
| 167 | +}); |
| 168 | +// Go To Previous Page |
| 169 | +document.getElementById('goToPreviousPage').addEventListener('click', () => { |
| 170 | +viewer.navigation.goToPreviousPage(); |
| 171 | +}); |
| 172 | + |
| 173 | +{% endhighlight %} |
| 174 | +{% endtabs %} |
| 175 | + |
| 176 | +Find the sample [here](https://stackblitz.com/edit/kpzmjpf7?file=index.js) to perform the page navigation options programmatically. |
| 177 | + |
| 178 | +## See also |
| 179 | + |
| 180 | +* [Toolbar items](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/javascript-es5/toolbar/) |
| 181 | +* [Feature modules](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/javascript-es5/feature-module/) |
0 commit comments