This guide shows how to build a Vue PDF viewer using the Apryse WebViewer SDK. You'll learn how to integrate the SDK into a Vue.js application to render, view, and interact with PDF documents using the WebViewer UI.
You can also download a ready-to-use GitHub sample to get started quickly, or explore the interactive Showcase demo to see WebViewer's full capabilities in action.
This guide assumes basic familiarity with Vue.js development. Before you start:
Apryse collects some data regarding your usage of the SDK for product improvement.
If you wish to continue without data collection, contact us and we will email you a no-tracking trial key for you to get started.
In this section, you’ll create a new Vue.js application using npm. This project provides the foundation for integrating Apryse WebViewer. If you already have a Vue app, skip this and continue to Install WebViewer.
webviewer-vue Vue 3 project using the official Vue tooling and a minimal setup:Flags are used to skip prompts during project configuration. The setup skips all example code and starts with a blank Vue project. Select different options if preferred.
3. Complete the setup prompts with the following settings. Select different options if preferred:
4. Navigate to your new Vue project directory and install Vue dependencies:
Next, install the Apryse WebViewer SDK using npm. This command adds the WebViewer package to your project, allowing you to integrate the PDF viewer and editor into your Vue application.
After navigating to your webviewer-vue project directory, run the following command to install WebViewer:
WebViewer needs access to its static assets at runtime, including WebAssembly modules, HTML, and CSS files. In a Vue project, you must copy these assets into the public directory so they can be served correctly. For more, see Copying WebViewer static assets.
public/lib/webviewer directory if it doesn't already exist:2. Copy all WebViewer static assets from node_modules/@pdftron/webviewer/public into the new public/lib/webviewer directory:
Your project should now include a similar structure:
The path option used when initializing WebViewer must point to this directory (for example, /lib/webviewer). If the path is incorrect, WebViewer will fail to load.
In this section, you'll add WebViewer to your Vue app by creating a component and initializing the viewer. This mounts the WebViewer UI and loads a document in your application.
components folder in your project's src directory:2. Create a WebViewer.vue file in the components folder:
3. In Visual Studio Code, add this code to the WebViewer.vue file and save:
src/components/WebViewer.vue
If you're signed in with an Apryse account, your license key is automatically prepopulated in all code snippets.
4. Replace the contents of the src/App.vue file with the following and save:
src/App.vue
If WebViewer doesn't appear in your application, verify that the container element has proper CSS dimensions. WebViewer automatically fills the full width and height of the element it's mounted to.
You can now load and display a PDF document in the WebViewer UI. Run your Vue application to launch WebViewer and see the PDF in your browser.
1. From your project directory, run the following command to start the application:
A successful output looks similar to:
2. Open the localhost URL from your terminal to view the WebViewer UI and PDF document.
In this 4-minute video, learn the fundamentals of Apryse WebViewer, including key concepts for installation and initialization in any web application.
Overview of Apryse WebViewer fundamentals, including installation and initialization.
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales