Getting Started with Syncfusion PDF Viewer in Vue 3

24 Jun 20265 minutes to read

This section explains how to create a Vue 3 application with Vite and integrate the Syncfusion® Vue PDF Viewer component using either the Composition API or Options API.

API Approaches

Composition API – A modern approach to organizing component logic by composing smaller, reusable functions. This method offers better code organization and reusable for complex components.

Options API – The traditional Vue approach that organizes component logic into a series of options (data, methods, computed properties, watchers, life cycle hooks, etc.).

Prerequisites

Install Node.js (version 18 or later recommended) along with npm or Yarn before creating the project. Review the system requirements for Vue UI components to confirm supported platforms.

Set up the Vite project

Use Vite to quickly scaffold a Vue 3 project. Run one of the following commands to create a new project:

npm create vite@latest
yarn create vite

After running the command, follow the interactive prompts shown below to configure the project:

  1. Define the project name: Specify the project name directly. This guide uses my-project.
  ? Project name: » my-project
  1. Select Vue as the framework to target Vue 3.
  ? Select a framework: » - Use arrow-keys. Return to submit.
  Vanilla
  > Vue
    React
    Preact
    Lit
    Svelte
    Others
  1. Choose JavaScript as the variant to build the Vite project with JavaScript and Vue.
  ? Select a variant: » - Use arrow-keys. Return to submit.
  > JavaScript
    TypeScript
    Customize with create-vue ↗
    Nuxt ↗
  1. After the scaffold completes, install the project dependencies:
cd my-project
  npm install
cd my-project
  yarn install

Add Syncfusion® Vue packages

Install the @syncfusion/ej2-vue-pdfviewer package using npm or Yarn. This package includes the PDF Viewer component and all required dependencies:

npm install @syncfusion/ej2-vue-pdfviewer --save
yarn add @syncfusion/ej2-vue-pdfviewer

Import Syncfusion® CSS styles

This section uses the Material theme. Import the required CSS into the <style> section of src/App.vue:

<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-pdfviewer/styles/material.css';
</style>

NOTE

For full details, see the themes documentation.

Add Syncfusion® Vue component

Add the PDF Viewer component to your Vue 3 application by following these instructions:

Import and register the PDF Viewer

Import the PDF Viewer component and required modules in the <script> section of src/App.vue.

import { provide } from 'vue';
import { PdfViewerComponent as EjsPdfviewer, Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView,
  ThumbnailView, Print, TextSelection, TextSearch, Annotation, FormDesigner, FormFields } from '@syncfusion/ej2-vue-pdfviewer';

const serviceUrl = 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer';
const documentPath = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
const pdfViewer = null;

provide('PdfViewer', [ Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView,
                       Print, TextSelection, TextSearch, Annotation, FormDesigner, FormFields]);
import { PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView,
           ThumbnailView, Print, TextSelection, TextSearch, Annotation, FormDesigner, FormFields } from '@syncfusion/ej2-vue-pdfviewer';

  export default {
    name: 'App',

    components: {
      "ejs-pdfviewer": PdfViewerComponent
    },

    data() {
      return {
        serviceUrl: "https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer",
        documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
      };
    },
    provide: {
      PdfViewer: [ Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView,
                   Print, TextSelection, TextSearch, Annotation, FormDesigner, FormFields ]
    }
  }

serviceUrl – The back-end endpoint for PDF processing. The Syncfusion-hosted URL provides evaluation capabilities. For production, replace with your deployed web service endpoint.

documentPath – The URL or file path to the PDF document to display.

Initialize the PDF Viewer

Add the PDF Viewer component markup to the <template> section of src/App.vue:

<ejs-pdfviewer id="pdfViewer" :serviceUrl="serviceUrl" :documentPath="documentPath">
</ejs-pdfviewer>

Run the project

Run the following command to start the Vue application:

npm run dev
yarn run dev

The application renders the PDF Viewer as shown below:

Vue PDF Viewer running in a Vite app

View sample in GitHub.

NOTE

Looking for the full Vue PDF Viewer component overview, features, pricing, and documentation? Visit the Vue PDF Viewer page.