- Component Initialization with CDN link for script and style reference
Contact Support
Getting started in Standalone PDF Viewer control
25 Mar 20255 minutes to read
The Essential JS 2 for JavaScript (global script) is an ES5 formatted pure JavaScript framework which can be directly used in latest web browsers.
Component Initialization with CDN link for script and style reference
Step 1: Create an app folder my-app
for the Essential JS 2 JavaScript components.
Step 2: The Essential JS 2 component’s global scripts and styles are already hosted in the below CDN link formats.
Syntax:
Script:
https://cdn.syncfusion.com/ej2/{Version}/dist/{PACKAGE_NAME}.min.js
Styles:
https://cdn.syncfusion.com/ej2/{Version}/{PACKAGE_NAME}/styles/material.css
Example:
Script:
https://cdn.syncfusion.com/ej2/26.2.11/dist/ej2.min.js
Styles:
https://cdn.syncfusion.com/ej2/26.2.11/ej2-base/styles/material.css
Step 3: Create a HTML page (index.html) in my-app
location and add the CDN link references. Now, add the Div
element and initiate the Essential JS 2 PDF Viewer
component in the index.html by using following code.
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>
<title>Essential JS 2</title>
<!-- Essential JS 2 material theme -->
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-pdfviewer/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-navigations/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-dropdowns/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-lists/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-splitbuttons/styles/material.css" rel="stylesheet">
<!-- Essential JS 2 PDF Viewer's script -->
<script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<!--element which is going to render-->
<div id="container">
<div id="PdfViewer" style="height:580px;width:100%;"></div>
</div>
<script>
//Initialize PDF Viewer component
var pdfviewer = new ej.pdfviewer.PdfViewer({
documentPath:'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf',
resourceUrl:'https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2-pdfviewer-lib'
});
ej.pdfviewer.PdfViewer.Inject(ej.pdfviewer.TextSelection, ej.pdfviewer.TextSearch, ej.pdfviewer.Print, ej.pdfviewer.Navigation, ej.pdfviewer.Toolbar,ej.pdfviewer.Magnification, ej.pdfviewer.Annotation, ej.pdfviewer.FormDesigner, ej.pdfviewer.FormFields, ej.pdfviewer.PageOrganizer);
//PDF Viewer control rendering starts
pdfviewer.appendTo('#PdfViewer');
</script>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
</body></html>
Steps to Load PDF Viewer with Local Resources
To use local resources with your PDF Viewer, follow these steps:
Step 1: Ensure that your application includes the ej2-pdfviewer-lib
folder. This folder must contain the pdfium.js
, pdfium.wasm
files, and the PDF file that you intend to display. These should reside in the same location as the ej2.min.js
script and its related styles.
Step 2: Assign local file paths to the documentPath
and resourceUrl
properties within the PDF Viewer setup. The documentPath
should refer to your PDF file, while the resourceUrl
should point to the directory containing the supporting resources.
Step 3: Insert the necessary script and style references within the <head>
section of your HTML file. Make sure these point to your local copies of the files instead of CDN links.
By following these steps, you will configure your PDF Viewer to load the required resources locally. See the code snippet below for reference.
<script>
var pdfviewer = new ej.pdfviewer.PdfViewer({
documentPath:window.location.origin +'/resources/pdfsuccinctly.pdf',
resourceUrl:window.location.origin +'/resources/ej2-pdfviewer-lib'
});
</script>
View the sample in GitHub to load PDF Viewer with local resources
Step 4: Now, run the index.html
in web browser, it will render the Essential JS 2 PDF Viewer
component.