Search results

Getting started with JavaScript PDF Viewer control

This section explains the steps to create a PDF Viewer within your application and demonstrate its basic usage.


The following are the list of minimum dependencies required to use the PDF Viewer:-

|-- @syncfusion/ej2-pdfviewer
    |-- @syncfusion/ej2-base
    |-- @syncfusion/ej2-buttons
    |-- @syncfusion/ej2-dropdowns
    |-- @syncfusion/ej2-inputs
    |-- @syncfusion/ej2-lists
    |-- @syncfusion/ej2-navigations
    |-- @syncfusion/ej2-popups
    |-- @syncfusion/ej2-data
    |-- @syncfusion/ej2-notifications

Installation and configuration

To get started with PDF Viewer component, you can clone the Essential JS 2 quickstart project and install necessary packages by using the following commands.

git clone quickstart
cd quickstart
npm install

Configuration system JS

Syncfusion PdfViewer packages should be mapped in the system.config.js configuration file.

    paths: {
        'syncfusion:': './node_modules/@syncfusion/',
    map: {
        app: 'app',

        //Syncfusion packages mapping
        "@syncfusion/ej2-base": "syncfusion:ej2-base/dist/ej2-base.umd.min.js",
        "@syncfusion/ej2-buttons": "syncfusion:ej2-buttons/dist/ej2-buttons.umd.min.js",
        "@syncfusion/ej2-popups": "syncfusion:ej2-popups/dist/ej2-popups.umd.min.js",
        "@syncfusion/ej2-navigations": "syncfusion:ej2-navigations/dist/ej2-navigations.umd.min.js",
        "@syncfusion/ej2-inputs": "syncfusion:ej2-inputs/dist/ej2-inputs.umd.min.js",
        "@syncfusion/ej2-splitbuttons": "syncfusion:ej2-splitbuttons/dist/ej2-splitbuttons.umd.min.js",
        "@syncfusion/ej2-dropdowns": "syncfusion:ej2-dropdowns/dist/ej2-dropdowns.umd.min.js",
        "@syncfusion/ej2-lists": "syncfusion:ej2-lists/dist/ej2-lists.umd.min.js",
        "@syncfusion/ej2-data": "syncfusion:ej2-data/dist/ej2-data.umd.min.js",
        "@syncfusion/ej2-notifications": "syncfusion:ej2-notifications/dist/ej2-notifications.umd.min.js",
        "@syncfusion/ej2-pdfviewer": "syncfusion:ej2-pdfviewer/dist/ej2-pdfviewer.umd.min.js"

    packages: {
        'app': { main: 'app', defaultExtension: 'js' }


Adding CSS reference

Combined CSS files are available in the Essential JS 2 package root folder. This can be referenced in your [src/styles/styles.css] using the following code.

@import '../../node_modules/@syncfusion/ej2/material.css';

To learn about individual component CSS, please refer to Individual Component theme files section.

Adding PdfViewer component

You can add Essential JS 2 PDF Viewer component to the application. To get started, add the PdfViewer component in app.ts and index.html files using the following code.

Place the following code in the app.ts

import { PdfViewer } from '@syncfusion/ej2-pdfviewer';

let pdfviewer: PdfViewer = new PdfViewer();
pdfviewer.serviceUrl = "http://localhost:62869/api/pdfviewer";

For PDF Viewer serviceUrl creation, follow the steps provided in the link

Now, add an HTML div element to act as the PDF Viewer element ‘index.html’ using the following code.

<!DOCTYPE html>
<html lang="en">

    <title>Essential JS 2</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
    <meta name="description" content="Essential JS 2" />
    <meta name="author" content="Syncfusion" />
    <link rel="shortcut icon" href="resources/favicon.ico" />
    <link href="" rel="stylesheet" />

    <!--style reference from app-->
    <link href="/styles/styles.css" rel="stylesheet" />

    <!--system js reference and configuration-->
    <script src="node_modules/systemjs/dist/system.src.js" type="text/javascript"></script>
    <script src="system.config.js" type="text/javascript"></script>

    <!--Element which will render as PdfViewer -->
    <div id="PdfViewer"></div>


Module injection

To create PDF Viewer with additional features, inject the required modules. The following modules are used to extend PdfViewer’s basic functionality:-

  • LinkAnnotation:- Inject this module to use PDF Viewer link annotation.
  • BookmarkView:- Inject this module to use bookmark view of the PDF Viewer.
  • Magnification:- Inject this module to magnify the PDF Document.
  • Navigation:- Inject this module to use page navigation on PDF Document.
  • TextSelection:- Inject this module to use text selection with the PDF Document.
  • ThumbnailView:- Inject this module to use thumbnail view of the PDF Viewer
  • Toolbar:- Inject this module to enable the user interface for toolbar option in PDF Viewer.
  • Print:- Inject this module to use pdfviewer print feature.
  • Annotation:- Inject this module to use pdfviewer annotation feature.

These modules should be injected into the PDF Viewer using PdfViewer.Inject method.

Run the application

The quickstart project is configured to compile and run the application in the browser. Use the following command to run the application.

npm start

Output will be displayed as follows.

import { PdfViewer, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection} from '@syncfusion/ej2-pdfviewer';

PdfViewer.Inject(Toolbar,Magnification,Navigation, Annotation, LinkAnnotation,ThumbnailView,BookmarkView, TextSelection);

let pdfviewer: PdfViewer = new PdfViewer();
pdfviewer.serviceUrl = '';
pdfviewer.load('PDF_Succinctly.pdf', null);
<!DOCTYPE html>
<html lang="en">

    <title>EJ2 PDF Viewer</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript PDF Viewer Control" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//" rel="stylesheet" />    
    <link href="//" rel="stylesheet" />
    <link href="//" rel="stylesheet" />
    <link href="//" rel="stylesheet" />
    <link href="//" rel="stylesheet" />
    <link href="//" rel="stylesheet" />
    <link href="//" rel="stylesheet" />
    <link href="//" rel="stylesheet" />    
    <link href="//" rel="stylesheet" />
    <link href="//" rel="stylesheet" />
    <script src=""></script>
    <script src="systemjs.config.js"></script>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='PdfViewer' style="height:500px;width:100%;"></div>