PDFObject Vue 3 Component

0.0.5 · active · verified Sun Apr 19

pdfobject-vue is an official Vue 3 component designed to facilitate the embedding of PDF documents directly into Vue applications. It serves as a declarative and reactive wrapper for the underlying PDFObject JavaScript utility. Currently at version 0.0.5, this package offers a `<PdfObject>` component that accepts a PDF `url` and `options` (matching the core PDFObject API) as props, simplifying what would otherwise be direct DOM manipulation. As a relatively new and early-stage project, its release cadence is currently irregular, but it benefits from leveraging the mature PDFObject library itself. A key differentiator is its status as the official Vue 3 integration, ensuring compatibility and adherence to best practices for both libraries. It aims to provide a seamless, idiomatic Vue experience for PDF embedding, handling the complexities of the underlying utility.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to register pdfobject-vue globally in `main.ts` and then use the `<PdfObject>` component in a Vue single-file component (`.vue` file) with props for the PDF URL and advanced options. It provides a complete, runnable example, including basic styling.

// main.ts (or main.js)
import { createApp } from 'vue';
import App from './App.vue';
import PDFObjectPlugin from 'pdfobject-vue';

const app = createApp(App);
app.use(PDFObjectPlugin); // Register the PDFObject Vue plugin globally
app.mount('#app');

// App.vue (or any Vue component where you want to embed a PDF)
<script setup lang="ts">
import { PdfObject } from 'pdfobject-vue';

// Define the URL for your PDF document
const pdfUrl = '/documents/sample.pdf'; // Ensure this path is accessible

// Define options for PDFObject (e.g., height, initial page, zoom)
const pdfOptions = {
  height: '600px', // Set the height of the embedded PDF viewer
  pdfOpenParams: { 
    view: 'FitV', // Fit view to width
    page: 1 
  } 
};
</script>

<template>
  <div id="app">
    <h1>My Document Viewer</h1>
    <p>Below is an embedded PDF document:</p>
    
    <!-- Use the PdfObject component to embed the PDF -->
    <PdfObject :url="pdfUrl" :options="pdfOptions" />

    <p>For more configuration options, refer to <a href="https://pdfobject.com" target="_blank">PDFObject.com</a>.</p>
  </div>
</template>

<style>
body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background-color: #f4f4f4; }
#app { max-width: 960px; margin: 20px auto; background-color: #fff; padding: 30px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
h1 { color: #333; margin-bottom: 15px; }
p { color: #666; line-height: 1.6; }
a { color: #007bff; text-decoration: none; }
a:hover { text-decoration: underline; }
</style>

view raw JSON →