Vue PDF Embed Component

2.1.4 · active · verified Sun Apr 19

vue-pdf-embed is a Vue 3 component designed for rendering PDF documents within web applications. It leverages PDF.js internally to provide features like controlled rendering, handling password-protected documents, and including interactive text and annotation layers. The current stable version is 2.1.4, released frequently with minor updates and patches, often updating its internal PDF.js dependency. Key differentiators include its simplicity, direct browser usability via unpkg, and lack of additional peer dependencies beyond Vue itself, making it easy to integrate into Vue 3 projects. It explicitly supports only Vue 3; for Vue 2, users must install `vue-pdf-embed@1`. It offers fine-grained control over PDF display, including page rotation, scaling, and selective page rendering.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to embed a PDF using `VuePdfEmbed`, including importing necessary styles, setting the PDF source, and dynamically controlling page navigation and rotation with reactive Vue refs.

<script setup>
import { ref } from 'vue';
import VuePdfEmbed from 'vue-pdf-embed';

// Optional styles for text selection and annotations
import 'vue-pdf-embed/dist/styles/annotationLayer.css';
import 'vue-pdf-embed/dist/styles/textLayer.css';

const pdfSource = ref('https://example.com/sample.pdf'); // Replace with your PDF URL
const page = ref(1);
const rotation = ref(0);

// Example of changing page or rotation dynamically
function goToNextPage() {
  page.value++;
}

function rotatePdf() {
  rotation.value = (rotation.value + 90) % 360;
}
</script>

<template>
  <div>
    <h1>My Document Viewer</h1>
    <button @click="goToNextPage">Next Page</button>
    <button @click="rotatePdf">Rotate PDF</button>
    <VuePdfEmbed 
      annotation-layer 
      text-layer 
      :source="pdfSource" 
      :page="page" 
      :rotation="rotation"
      height="500"
    />
  </div>
</template>

view raw JSON →