1.1.7 • Published 1 year ago

vue-pdf-embed-up v1.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

📄 vue-pdf-embed

升级测试 PDF embed component for Vue 2 and Vue 3

Awesome npm npm GitHub Repo stars npm

Features

  • Controlled rendering of PDF documents in Vue apps
  • Handles password protected documents
  • Includes text layer (searchable and selectable documents)
  • Includes annotation layer (annotations and links)
  • No peer dependencies or additional configuration required
  • Can be used directly in the browser (see Examples)

Compatibility

This package is compatible with both Vue 2 and Vue 3, but consists of two separate builds. The default exported build is for Vue 3, for Vue 2 import dist/vue2-pdf-embed.js (see Usage).

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:application/pdf;base64,<BASE64_ENCODED_PDF>',
    }
  },
}
</script>

Props

NameTypeAccepted valuesDescription
disableAnnotationLayerbooleantrue or falsewhether the annotation layer should be disabled
disableTextLayerbooleantrue or falsewhether the text layer should be disabled
heightnumber stringnatural numbersdesired page height in pixels (ignored if the width property is specified)
imageResourcesPathstringURL or path with trailing slashpath for icons used in the annotation layer
pagenumber1 to the last page numbernumber of the page to display (displays all pages if not specified)
rotationnumber string0, 90, 180 or 270 (multiples of 90)desired page rotation angle in degrees
scalenumberrational numbersdesired ratio of canvas size to document size
sourcestring object Uint8Arraydocument URL or typed array pre-filled with datasource of the document to display
widthnumber stringnatural numbersdesired page width in pixels

Events

NameValueDescription
internal-link-clickeddestination page numberinternal link was clicked
loading-failederror objectfailed to load document
loadedPDF document proxyfinished loading the document
password-requestedcallback function, retry flagpassword is needed to display the document
rendering-failederror objectfailed to render document
rendered–finished rendering the document
printing-failederror objectfailed to print document
progressprogress params objecttracking document loading progress

Public Methods

NameArgumentsDescription
render–manually (re)render document
printprint resolution (number), filename (string), all pages flag (boolean)print document via browser interface

Static Methods

Besides the component itself, the module also includes a getDocument function for manual loading of PDF documents, which can then be used as the source prop of the component. In most cases it is sufficient to specify the source prop with a URL or typed array, while the result of the getDocument function can be used in special cases, such as sharing the source between multiple component instances. This is an advanced topic, so it is recommended to check the source code of the component before using this function.

Examples

Basic Usage Demo (JSFiddle)

Advanced Usage Demo (JSFiddle)

Advanced Usage Demo (StackBlitz)

License

MIT License. Please see LICENSE file for more information.

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago