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 Overflow
🌐
Nutrient
nutrient.io › blog › sdk › how to generate a pdf with vuejs
Vue PDF generation: Convert HTML to PDF with html2pdf.js in Vue.js
June 19, 2025 - Once complete, navigate into your project directory: ... html2pdf.js is a lightweight library that converts HTML elements into downloadable PDFs by capturing them as canvases and passing the output to jsPDF.
🌐
npm
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
🌐
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%
🌐
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%
🌐
PDF.js Express
pdfjs.express › documentation › get-started › vue
Integrate Vue.js & JavaScript PDF Viewer | PDF.js Express SDK
Welcome to PDF.js Express. This guide will help you integrate a free trial of PDF.js Express into VueJS applications on the browser. It will help you clone the Vue sample repository, walk through the project structure, and show you how to call other WebViewer API.
🌐
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
A PDF viewer for Vue using Mozilla's PDF.js that supports both Vue2 and Vue3 - arkokoley/pdfvuer
Starred by 948 users
Forked by 132 users
Languages   Vue 68.2% | JavaScript 31.8%
Find elsewhere
🌐
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
    
Published   Dec 04, 2025
Version   3.5.1
Author   Vue PDF 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
🌐
PDF.js Express
pdfjs.express › blog › how-to-build-a-pdf-viewer-with-vuejs
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.
🌐
Made with Vue.js
madewithvuejs.com › vuepdf
VuePDF - PDF Viewer Component - Made with Vue.js
September 25, 2023 - "VuePDF is a Vue 3 client-side component for pdf.js that allows you to flexibly display PDF pages within your project.
🌐
Vue PDF Viewer
blog.vue-pdf-viewer.dev › building-a-pdf-viewer-for-vuejs-with-pdfjs-vue3-pdf-app-and-more
Building a PDF Viewer for Vue.js with PDF.js, vue3-pdf-app and more
May 24, 2025 - For example, you do not want to add a PDF iFrame. PDF.js is a powerful JavaScript library maintained by Mozilla that allows rendering and manipulation of PDF files directly in web browsers.
🌐
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
This project demonstrates how a simple PDF viewer could be implemented using 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%
🌐
PSPDFKit
pspdfkit.com › blog › sdk › how to build a vuejs pdf viewer with pdfjs
How to Build a Vue.js PDF Viewer with PDF.js
November 4, 2024 - PDF.js(opens in a new tab) is an open source JavaScript library that allows you to view PDF files in your browser. In the first part, we’ll look at how to create the PDF viewer with an open source library.
🌐
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
🌐
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%