Lightweight PDF viewer for optimization

Usage no npm install needed!

<script type="module">
  import clariokidsVuePdfOptimization from 'https://cdn.skypack.dev/@clariokids/vue-pdf-optimization';



PDF.js is very advanced JS library for parsing and displaying PDF files by Mozilla. This project aims to provide simple and lightweight Vue.js component, that downloads library files lazily from cdn with minimal setup.

Similar projects:

  • vue-pdf - includes PDF.js files into your bundle with webpack. Sometimes this may be undesirable because:
    • it may require additional webpack configuration
    • webpack processing can lead to issues
    • latest webpack has a bug in development mode with worker files
    • it will increase bundle size (pdf.js viewer + worker = about 800 kb) and build time.


yarn add vue-pdf-optimization
# or
npm install vue-pdf-optimization --save



<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
      <strong>We're sorry but vue-pdf-cdn doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    <div id="app"></div>
    <script  src="https://unpkg.com/pdfjs-dist@latest/build/pdf.min.js"></script>
    <!-- built files will be auto injected -->
        v-for="i in numPages"

import pdf from 'vue-pdf-optimization'

export default {
  components: {
  created() {
        const loadingTask = window.pdfjsLib.getDocument('pdf地址')
        this.src = loadingTask.promise
        this.src.then( pdf => {
            this.numPages = pdf.numPages


  • src - URL of PDF file to load and display


  • @status - triggered when status update happens (library initialized, pdf downloaded, etc.). Provides string describing status.
  • @error - triggered when error happens. Provides error message.
  • @loading - triggered when loading status changes. Provides boolean (true/false).