Build a Vue PDF viewer with Apryse WebViewer SDK
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.
Prerequisites
This guide assumes basic familiarity with Vue.js development. Before you start:
Install Node.js and npm. See the Vue.js documentation for version details.
Install Visual Studio Code or another code editor to develop and debug your code.
Get your Apryse trial key.
1. Create a Vue project
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.
In your terminal, go to the directory where you want to create the project.
Create a new
webviewer-vueVue 3 project using the official Vue tooling and a minimal setup:
npx --yes create-vue@latest webviewer-vue --bareComplete the setup prompts with the following settings. Select different options if preferred:
Don't use TypeScript.
Don't select any additional Vue or experimental features.
Navigate to your new Vue project directory and install Vue dependencies:
2. Install WebViewer
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:
3. Copy WebViewer assets
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.
From your project root, create the
public/lib/webviewerdirectory if it doesn't already exist:
Copy all WebViewer static assets from
node_modules/@pdftron/webviewer/publicinto the newpublic/lib/webviewerdirectory:
Your project should now include a similar structure:
4. Create the PDF viewer
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.
Create a
componentsfolder in your project'ssrcdirectory:
Create a
WebViewer.vuefile in thecomponentsfolder:
In Visual Studio Code, add this code to the
WebViewer.vuefile and save:
Replace the contents of the
src/App.vuefile with the following and save:
5. Verify your output
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.
From your project directory, run the following command to start the application:
A successful output looks similar to:
Open the localhost URL from your terminal to view the WebViewer UI and PDF document.
Get started video
In this 4-minute video, learn the fundamentals of Apryse WebViewer, including key concepts for installation and initialization in any web application.
Next steps
Last updated
Was this helpful?