I think the error occurs if pdfjsLib does not fall into the global scope , see also codesandbox :
<template>
<div id="pageContainer">
<div id="viewer" class="pdfViewer"></div>
</div>
</template>
<script>
import pdfjsLib from "pdfjs-dist/build/pdf";
import { PDFViewer } from "pdfjs-dist/web/pdf_viewer";
import "pdfjs-dist/web/pdf_viewer.css";
pdfjsLib.GlobalWorkerOptions.workerSrc =
"https://cdn.jsdelivr.net/npm/[email protected]/build/pdf.worker.min.js";
export default {
name: "PdfViewer",
props: { docPath: String },
mounted() {
this.getPdf();
},
methods: {
async getPdf() {
let container = document.getElementById("pageContainer");
let pdfViewer = new PDFViewer({
container: container,
});
let pdf = await pdfjsLib.getDocument(this.docPath);
pdfViewer.setDocument(pdf);
},
},
};
</script>
<style>
#pageContainer {
margin: auto;
width: 80%;
}
div.page {
display: inline-block;
}
</style>
use it:
<PdfViewer docPath="./sample.pdf" />
Answer from Daniil Loban on Stack Overflownpm
npmjs.com › package › vue-pdf
vue-pdf - npm
vue.js pdf viewer is a package for Vue that enables you to display and view PDF's easily via vue components.
» npm install vue-pdf
Published Jun 17, 2021
Version 4.3.0
Author Franck FREIBURGER
Repository https://github.com/FranckFreiburger/vue-pdf
Videos
11:56
Build a Vue.js HTML2PDF.js Example to Create PDF From Template ...
How To View PDF In Vue JS Tutorial (Easy Method)
05:37
How to Build a PDF Viewer and Editor in Vue.js with WebViewer - ...
03:05
How to Generate a PDF from HTML using Vue - YouTube
08:02
Getting Started with Vue PDF Viewer Component - YouTube
07:06
How to Build a Vue PDF Viewer - YouTube
GitHub
github.com › FranckFreiburger › vue-pdf
GitHub - FranckFreiburger/vue-pdf: vue.js pdf viewer
vue.js pdf viewer is a package for Vue that enables you to display and view PDF's easily via vue components.
Starred by 2.3K users
Forked by 533 users
Languages JavaScript 70.2% | CSS 20.5% | Vue 9.3%
Top answer 1 of 7
4
I think the error occurs if pdfjsLib does not fall into the global scope , see also codesandbox :
<template>
<div id="pageContainer">
<div id="viewer" class="pdfViewer"></div>
</div>
</template>
<script>
import pdfjsLib from "pdfjs-dist/build/pdf";
import { PDFViewer } from "pdfjs-dist/web/pdf_viewer";
import "pdfjs-dist/web/pdf_viewer.css";
pdfjsLib.GlobalWorkerOptions.workerSrc =
"https://cdn.jsdelivr.net/npm/[email protected]/build/pdf.worker.min.js";
export default {
name: "PdfViewer",
props: { docPath: String },
mounted() {
this.getPdf();
},
methods: {
async getPdf() {
let container = document.getElementById("pageContainer");
let pdfViewer = new PDFViewer({
container: container,
});
let pdf = await pdfjsLib.getDocument(this.docPath);
pdfViewer.setDocument(pdf);
},
},
};
</script>
<style>
#pageContainer {
margin: auto;
width: 80%;
}
div.page {
display: inline-block;
}
</style>
use it:
<PdfViewer docPath="./sample.pdf" />
2 of 7
3
In case anyone else needs it, the soution is really simple. You just have to import it like this:
import * as pdfjsLib from "pdfjs-dist/build/pdf";
GitHub
github.com › TaTo30 › vue-pdf
GitHub - TaTo30/vue-pdf: PDF component for Vue 3
VuePDF is a client-side component for Vue 3 that allows you to flexibly render PDF pages within your project. This library wraps pdf.js library so all main features of pdf.js are supported by VuePDF as well.
Starred by 642 users
Forked by 103 users
Languages TypeScript 60.7% | Vue 38.6%
Rossta
rossta.net › blog › building-a-pdf-viewer-with-vue-part-1.html
Rendering PDF pages with PDF.js and Vue - rossta.net
June 28, 2018 - This tutorial demonstrates how to create Vue.js components that can render PDFs along with tools like webpack, PDF.js, and the canvas element.
GitHub
github.com › arkokoley › pdfvuer
GitHub - arkokoley/pdfvuer: A PDF viewer for Vue using Mozilla's PDF.js that supports both Vue2 and Vue3
Starred by 948 users
Forked by 132 users
Languages Vue 68.2% | JavaScript 31.8%
npm
npmjs.com › package › @vue-pdf-viewer › viewer
vue-pdf-viewer/viewer
Save Weeks of Development Time: Vue PDF Viewer simplifies PDF integration with ready-to-use tools, minimizing the need for custom development and saving you valuable time. Tailored for Vue.js & Nuxt.js: Vue PDF Viewer is native to Vue.js, ensuring ...
» npm install @vue-pdf-viewer/viewer
npm
npmjs.com › package › vue-pdf-embed
vue-pdf-embed - npm
The web worker used to handle PDF documents is loaded by default. However, this may not be acceptable due to bundler restrictions or CSP (Content Security Policy). In such cases it is recommended to use the essential build (index.essential.mjs) and set up the worker manually using the exposed GlobalWorkerOptions. import { GlobalWorkerOptions } from 'vue-pdf-embed/dist/index.essential.mjs' import PdfWorker from 'pdfjs-dist/build/pdf.worker.mjs?url' GlobalWorkerOptions.workerSrc = PdfWorker
» npm install vue-pdf-embed
Published Jul 14, 2025
Version 2.1.3
Author Aliaksei Hrynko
Repository https://github.com/hrynko/vue-pdf-embed
PDF.js Express
pdfjs.express › blog › how-build-pdf-viewer-vuejs-pdfjs
How to Build a PDF Viewer With Vue.js | Apryse
July 8, 2019 - This guide shows how to use Vue.js PDF viewer to integrate PDF viewing, signing, review and approval, redaction and more as part of your web app using Vue, inside a single secure environment that can take care of version control as well.
Vue PDF Viewer
vue-pdf-viewer.dev
Vue PDF Component - Easy to Use | Vue PDF Viewer
The best choice for Vue.js developers looking to display PDF on Vue 3 and Nuxt websites.
GitHub
github.com › rossta › vue-pdfjs-demo
GitHub - rossta/vue-pdfjs-demo: A demo PDF viewer implemented with Vue and PDF.js
Starred by 454 users
Forked by 126 users
Languages Vue 88.3% | JavaScript 7.2% | HTML 1.7% | Ruby 1.5% | Shell 1.3%
npm
npmjs.com › package › vue3-pdfjs
vue3-pdfjs - npm
PDF Reader for Vue 3 using Mozilla's PDF.js. Latest version: 0.1.6, last published: 4 years ago. Start using vue3-pdfjs in your project by running `npm i vue3-pdfjs`. There are 20 other projects in the npm registry using vue3-pdfjs.
» npm install vue3-pdfjs
Published Oct 09, 2021
Version 0.1.6
Author Randolph Tellis
Repository https://github.com/randolphtellis/vue3-pdfjs
PDF.js Express
pdfjs.express › documentation › vue
Vue.js PDF.js Viewer: Annotate, Form Fill, Sign | PDF.js Express
PDF.js Express is a commercial PDF web viewer that wraps around the PDF.js open-source rendering engine. It offers developers a way to quickly add annotation, e-signatures, and form filling to their Vue.js PDF viewer.
GitHub
github.com › sandanat › vue-pdf-app
GitHub - sandanat/vue-pdf-app: VUEjs v2 PDF viewer based on Mozilla's PDFJS
VUEjs v2 PDF viewer based on Mozilla's PDFJS. Contribute to sandanat/vue-pdf-app development by creating an account on GitHub.
Starred by 242 users
Forked by 116 users
Languages JavaScript 94.9% | SCSS 1.4% | Vue 1.4% | CSS 1.2%