Integrate WebViewer into a Vue.js Project

Using a Vue project (scaffolded using vite through create-vue), WebViewer is defined in a Vue component and added to the project. The component is able to view, annotate, and manipulate PDFs and other documents.

The sample also demonstrates how to programmatically add a rectangle annotation with user-defined dimensions. For more information, see this guide.

WebViewer provides a slick out-of-the-box responsive UI that enables you to view, annotate and manipulate PDFs and other document types inside any web project.

Click the button below to view the full project in GitHub.

1<template>
2 <div id="webviewer" ref="viewer"></div>
3</template>
4
5<script>
6import { ref, onMounted } from 'vue';
7import WebViewer from '@pdftron/webviewer';
8
9export default {
10 name: 'WebViewer',
11 props: { initialDoc: { type: String } },
12 setup(props) {
13 const viewer = ref(null);
14 onMounted(() => {
15 WebViewer({
16 path: '/lib/webviewer',
17 initialDoc: props.initialDoc,
18 licenseKey: 'your_license_key' // sign up to get a free trial key at https://dev.apryse.com
19 }, viewer.value).then(
20 (instance) => {
21 const { documentViewer, annotationManager, Annotations } =
22 instance.Core;
23
24 documentViewer.addEventListener('documentLoaded', () => {
25 const rectangleAnnot = new Annotations.RectangleAnnotation({
26 PageNumber: 1,
27 // values are in page coordinates with (0, 0) in the top left
28 X: 100,
29 Y: 150,
30 Width: 200,
31 Height: 50,
32 Author: annotationManager.getCurrentUser(),
33 });
34 annotationManager.addAnnotation(rectangleAnnot);
35 annotationManager.redrawAnnotation(rectangleAnnot);
36 });
37 }
38 );
39 });
40 return {
41 viewer,
42 };
43 },
44};
45</script>
46
47<style>
48#webviewer {
49 height: 100vh;
50}
51</style>
52

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales