Steps I performed which solved my problem.
Install pdfjs-dist.
npm install pdfjs-distSecond step this is something you have to do, if you get below error,
op-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)
- It has to do with
vite.config.jsfile. - I found solution for that from this post.
Add below code in your
vite.config.jsfile.
build: {
target: "es2022"
},
esbuild: {
target: "es2022"
},
optimizeDeps:{
esbuildOptions: {
target: "es2022",
}
}
- Then you need to import file like this,
import * as pdfjsLib from "pdfjs-dist";
import * as pdfWorker from "pdfjs-dist/build/pdf.worker.mjs";
if you will not import second then you might get below error.
Answer from Nixit Ahir on Stack OverflowpdfWorker is not defined
» npm install @vue-pdf-viewer/viewer
Videos
» npm install pdf-vue3
» npm install vue3-pdfjs
» npm install vue3-pdf-app
I found out the issue was scoped CSS. Since the element renders later, the scoped CSS wasn't getting applied. Below is the imported css that needs to be in an unscoped style tag.
@import '../../node_modules/pdfjs-dist/web/pdf_viewer.css';
- Install the pdfjs-dist library:
npm i pdfjs-dist
Locate the
pdf.worker.min.mjsfile in thenode_modules/pdfjs-dist/builddirectory and copy it to thepublicdirectory.Import it in your component:
import * as pdfjsLib from "pdfjs-dist";
import pdfWorker from "/pdf.worker.min.mjs?url";
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfWorker;
» npm install vue3-pdf
Hello Vuejs community! I'm excited to share my open-source project, 'PDF-Frame-Vue', designed specifically for Vue applications. It's a framework that allows you to create interactive and visually rich PDFs and Canvas graphics with its intuitive HTML template syntax.
I would love to get your feedback and support on this. It's crafted to enhance the capabilities of Vue apps. Looking forward to hearing your thoughts and suggestions! Attaching a blog along with the examples for your reference.
Blog: ://nswamy14.hashnode.dev/creating-visually-rich-pdfs-with-pdf-frame-vue
Github Repo: https://github.com/I2Djs/pdf-frame
Pdf Example: https://stackblitz.com/edit/pdf-frame-vuejs
Canvas Example: https://stackblitz.com/edit/pdf-frame-vuejs-canvas-qp1rhy
Vue 3 component for PDF and Canvas graphics
» npm install vue-pdf-embed