npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-pdf-embed

v2.1.1

Published

PDF embed component for Vue

Downloads

187,156

Readme

📄 vue-pdf-embed

PDF embed component for Vue 3 (see Compatibility for Vue 2 support)

Awesome List npm Version npm Downloads GitHub Stars License

Features

  • Controlled rendering of PDF documents in Vue apps
  • Handling 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 only compatible with Vue 3. For Vue 2 support, install vue-pdf-embed@1 and refer to the v1 docs.

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

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

// optional styles
import 'vue-pdf-embed/dist/styles/annotationLayer.css'
import 'vue-pdf-embed/dist/styles/textLayer.css'

// either URL, Base64, binary, or document proxy
const pdfSource = '<PDF_URL>'
</script>

<template>
  <VuePdfEmbed annotation-layer text-layer :source="pdfSource" />
</template>

Props

| Name | Type | Accepted values | Description | | ------------------ | ---------------------- | ------------------------------------------------------- | -------------------------------------------------------------------------- | | annotationLayer | boolean | true or false | whether the annotation layer should be enabled | | height | number | natural numbers | desired page height in pixels (ignored if the width property is specified) | | imageResourcesPath | string | URL or path with trailing slash | path for icons used in the annotation layer | | page | number | 1 to the last page number | number of the page to display (displaying all pages if not specified) | | rotation | number | 0, 90, 180, 270 (multiples of 90) | desired page rotation angle in degrees | | scale | number | rational numbers | desired page viewport scale | | source | string object | document URL or Base64 or typed array or document proxy | source of the document to display | | textLayer | boolean | true or false | whether the text layer should be enabled | | width | number | natural numbers | desired page width in pixels |

Events

| Name | Value | Description | | --------------------- | ----------------------------------------------------------------------- | ------------------------------------------ | | internal-link-clicked | destination page number | internal link was clicked | | loaded | PDF document proxy | finished loading the document | | loading-failed | error object | failed to load document | | password-requested | object with callback function and isWrongPassword flag | password is needed to display the document | | progress | object with number of loaded pages along with total number of pages | tracking document loading progress | | rendered | – | finished rendering the document | | rendering-failed | error object | failed to render document |

Slots

| Name | Props | Description | | ----------- | -------------------- | ------------------------------------ | | after-page | page (page number) | content to be added after each page | | before-page | page (page number) | content to be added before each page |

Public Methods

| Name | Arguments | Description | | -------- | ---------------------------------------------------------------------------- | ------------------------------------ | | download | filename (string) | download document | | print | print resolution (number), filename (string), all pages flag (boolean) | print document via browser interface |

Note: Public methods can be accessed through a template ref.

Common Issues and Caveats

Server-Side Rendering

This is a client-side library, so it is important to keep this in mind when working with SSR (server-side rendering) frameworks such as Nuxt. Depending on the framework used, you may need to properly configure the library import or use a wrapper.

Web Worker Loading

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

Document Loading

Typically, document loading is internally handled within the component. However, for optimization purposes, the document can be loaded in the useVuePdfEmbed composable function and then passed as the source prop of the component (e.g. when sharing the source between multiple instances of the component).

<script setup>
import VuePdfEmbed, { useVuePdfEmbed } from 'vue-pdf-embed'

const { doc } = useVuePdfEmbed({ source: '<PDF_URL>' })
</script>

<template>
  <VuePdfEmbed :source="doc" />
</template>

Resources

The path to predefined CMaps should be specified to ensure correct rendering of documents containing non-Latin characters, as well as in case of CMap-related errors:

<VuePdfEmbed
  :source="{
    cMapUrl: 'https://unpkg.com/pdfjs-dist/cmaps/',
    url: '<PDF_URL>',
  }"
/>

The image resource path must be specified for annotations to display correctly:

<VuePdfEmbed
  image-resources-path="https://unpkg.com/pdfjs-dist/web/images/"
  source="<PDF_URL>"
/>

Note: The examples above use a CDN to load resources, however these resources can also be included in the build by installing the pdfjs-dist package as a dependency and further configuring the bundler.

Examples

Basic Usage Demo (JSFiddle)

Advanced Usage Demo (JSFiddle)

License

MIT License. Please see LICENSE file for more information.