Vue 2 & Vue 3 PDF Viewer Component

0.2.7 · active · verified Sun Apr 19

The `pdf-viewer-vue` package offers a straightforward Vue component for embedding and displaying PDF documents directly within Vue 2 and Vue 3 applications. It acts as a wrapper around the `vue-pdf` library, which itself leverages Mozilla's PDF.js for rendering PDF content. The current stable version is 0.2.7. This library is designed for developers seeking a basic, easy-to-integrate PDF viewer without the need for extensive customization or advanced interactive features like sophisticated annotations or form filling, which might be found in more comprehensive or commercially backed alternatives. Its release cadence has been infrequent, focusing primarily on maintaining compatibility with Vue versions 2 and 3.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate and display a PDF document using the PdfViewer component in a Vue 3 Composition API setup, with TypeScript.

<template>
  <div class="pdf-container">
    <h2>My Document Viewer</h2>
    <p>Displaying a sample PDF:</p>
    <PdfViewer src="https://www.africau.edu/images/default/sample.pdf" style="height: 500px; width: 100%;" />
    <p>This viewer supports both Vue 2 and Vue 3 applications.</p>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import PdfViewer from 'pdf-viewer-vue';

export default defineComponent({
  name: 'DocumentViewer',
  components: {
    PdfViewer,
  },
  setup() {
    // Composition API specific logic can go here
  },
});
</script>

<style scoped>
.pdf-container {
  border: 1px solid #eee;
  padding: 20px;
  border-radius: 8px;
  max-width: 800px;
  margin: 20px auto;
  box-shadow: 0 2px 12px rgba(0,0,0,0.05);
}
</h2 style="color: #333;">
</style>

view raw JSON →