1.0.6 • Published 2 years ago

@kevin-skylabx/vue-pdf-embed-skylabx v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

📄 vue-pdf-embed

PDF embed component for Vue 2 and Vue 3

Awesome npm npm GitHub Repo stars npm

Compatibility

This package is compatible with both Vue 2 and Vue 3. The default exported build is for Vue 3, but dist directory also contains a build for Vue 2 (dist/vue2-pdf-embed.js). See the example in Usage section.

Installation

Depending on the environment, the package can be installed in one of the following ways:

npm install vue-pdf-embed
yarn add vue-pdf-embed
<script src="https://unpkg.com/vue-pdf-embed"></script>

Usage

<template>
  <div>
    <h1>File</h1>

    <vue-pdf-embed :source="source1" />

    <h1>Base64</h1>

    <vue-pdf-embed :source="source2" />
  </div>
</template>

<script>
import VuePdfEmbed from 'vue-pdf-embed'

// OR THE FOLLOWING IMPORT FOR VUE 2
// import VuePdfEmbed from 'vue-pdf-embed/dist/vue2-pdf-embed'

export default {
  components: {
    VuePdfEmbed,
  },
  data() {
    return {
      source1: '<PDF_URL>',
      source2: {
        data: atob('<BASE64_ENCODED_PDF>'),
      },
    }
  }
})
</script>

Props

NameTypeAccepted valuesDescription
pagenumber1 to the number of the last pagenumber of the page to display (displays all pages if not specified)
sourcestring objectdocument URL or typed array pre-filled with datasource of the document to display

Events

NameValueDescription
loading-failederror objectfailed to load document
password-requestedcallback function, retry flagpassword is needed to display the document
rendering-failederror objectfailed to render document
renderedfinished rendering the document

Examples

Basic Usage Demo (JSFiddle)

Advanced Usage Demo (JSFiddle)

License

MIT License. Please see LICENSE file for more information.