This section explains how to use PDF Viewer component in Vue 3 application.
System requirements for Syncfusion Vue UI components
The easiest way to create a Vue application is to use the Vue CLI
. Vue CLI versions above 4.5.0
are mandatory for creating applications using Vue 3. Use the following command to uninstall older versions of the Vue CLI.
npm uninstall vue-cli -g
Use the following commands to install the latest version of Vue CLI.
npm install -g @vue/cli
npm install -g @vue/cli-init
Create a new project using the command below.
vue create quickstart
Add the below command to install npm to project.
cd quickstart
npm install
npm install vue-class-component@^8.0.0-rc.1
Initiating a new project prompts us to choose the type of project to be used for the current application. Select the option Default (Vue 3)
from the menu.
Syncfusion Vue packages are maintained in the npmjs.com
registry.
To install PDF Viewer component, use the following command.
npm install @syncfusion/ej2-vue-pdfviewer --save
The —save will instruct NPM to include the PDF Viewer package inside the
dependencies
section of thepackage.json
.
Import the needed css styles for the PDF Viewer component along with dependency styles in the <style>
section of the src/App.vue
file as follows.
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-lists/styles/material.css';
@import '../node_modules/@syncfusion/ej2-vue-pdfviewer/styles/material.css';
</style>
PDF Viewer component use other Syncfusion components too, the dependent component’s CSS references need to be added for using all the PDF Viewer functionalities.
You have completed all the necessary configurations needed for rendering the Syncfusion Vue component. Now, you are going to add the PDF viewer component using following steps.
Step 1: Import the PDF Viewer component in the <script>
section of the src/App.vue
file.
<script>
import { PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView, Print, TextSelection, TextSearch, Annotation, FormDesigner, FormFields } from '@syncfusion/ej2-vue-pdfviewer';
</script>
Step 2: Register the the PDF Viewer component in your application.
//Component registeration
export default {
name: 'App',
// Declaring component and its directives
components: {
"ejs-pdfviewer": PdfViewerComponent
},
Step 3: Add the component definition in template section.
<template>
<ejs-pdfviewer id="pdfViewer" :serviceUrl="serviceUrl" :documentPath="documentPath"> </ejs-pdfviewer>
</template>
Step 4: Declare the bound properties serviceUrl
and documentPath
in the script
section.
data () {
return {
serviceUrl:"https://ej2services.syncfusion.com/production/web-services/api/pdfviewer",
documentPath:"PDF_Succinctly.pdf"
};
},
Step 5: Summarizing the above steps, update the src/App.vue
file with following code.
<template>
<ejs-pdfviewer id="pdfViewer" :serviceUrl="serviceUrl" :documentPath="documentPath"> </ejs-pdfviewer>
</template>
<script>
import { PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView, Print, TextSelection, TextSearch, Annotation, FormDesigner, FormFields } from '@syncfusion/ej2-vue-pdfviewer';
//Component registeration
export default {
name: 'App',
// Declaring component and its directives
components: {
"ejs-pdfviewer": PdfViewerComponent
},
data () {
return {
serviceUrl:"https://ej2services.syncfusion.com/production/web-services/api/pdfviewer",
documentPath:"PDF_Succinctly.pdf"
};
},
provide: {
PdfViewer: [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView, Print, TextSelection, TextSearch, Annotation, FormDesigner, FormFields]
}
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-lists/styles/material.css';
@import '../node_modules/@syncfusion/ej2-vue-pdfviewer/styles/material.css';
#pdfViewer {
height: 640px;
}
</style>
Run the application using the following command.
npm run serve
Web server will be initiated, Open the quick start app in the browser at port localhost:8080
.