🚀 Launch a PDF Viewer in Nuxt Using @vue-pdf-viewer [Guide for 2025] 🔥

Kittisak MaKittisak Ma
8 min read

PDF viewing is now a must-have for modern web apps, from online contracts to digital classrooms. If you’re building with Nuxt, you want tools that fit right in and work fast. That’s where @vue-pdf-viewer shines 🌟

@vue-pdf-viewer lets you open, zoom, and interact with PDFs right inside your Vue or Nuxt project. The setup is quick, with features like keyboard controls, responsive layouts, and even advanced document options ready to go. For developers and teams, it’s a straightforward, reliable way to add rich PDF support to any Nuxt-powered app.

Disclaimer: I work at Vue PDF Viewer.


Why Choose @vue-pdf-viewer for Nuxt Applications

If you want smooth PDF handling in your Nuxt project, you need a component that just works. Vue PDF Viewer stands out for its balance of powerful features and simple setup. You can add the library into almost any Nuxt page or component with minimal setup. It's built for Nuxt and Vue, so you avoid heavy solutions or flaky workarounds.

Key Features that Set @vue-pdf-viewer Apart

Vue PDF Viewer offers everything most apps need right out of the box. Here’s what you get:

  • Smooth zoom and rotation: Users can view their PDFs up close, rotate pages, and not miss a detail.

  • Keyboard navigation: Move through documents without leaving the keyboard.

  • Responsive layouts: Fits devices big or small, so mobile users can scroll, zoom, and interact with ease.

  • PDF layers support: Support for text, canvas and annotation layers.

  • Search and text selection: Users find what they need fast, selecting and copying text directly from the PDF.

  • Easy customization: Vue PDF Viewer's toolbar or theme can be configured easily to fit your business needs.

If you want the full list, check the official documentation’s Feature Overview. You’ll see plenty of advanced options, but the defaults work for most projects.

Documentation Feature Overview

Several tools such as Apryse and Syncfusion compete in this space, but Vue PDF Viewer stands out for its simplicity and Vue-first design:

  • Vue-native: Compared to other PDF.js wrappers, Vue PDF Viewer is written entirely in Vue, which means fewer compatibility headaches.

  • Lightweight footprint: It’s lighter than some heavyweight tools like Apryse or Syncfusion.

  • Feature-rich yet accessible: While many open-source options lack advanced controls or built-in Nuxt support, Vue PDF Viewer gives you both out-of-the-box.

Where @vue-pdf-viewer Shines in Nuxt

You’ll see it in action everywhere—from simple PDF previews to interactive AI-powered PDF tools and full-fledged document management systems. It's a great fit for projects where:

  • âś… You need solid, bug-free PDF rendering.

  • âś… Custom UI or branding matters.

  • âś… Fast time-to-launch is key and the focus is on Vue or Nuxt development.

The component’s flexibility lets you scale from basic views to complex document tools without starting over each time.


Setting Up Your Nuxt Project for PDF Viewing

Getting your Nuxt project ready for PDF viewing starts with a solid foundation. You'll want installation to be smooth and straightforward asset handling to ensure reliable PDF rendering and easy file maintenance.

Install Dependencies and Project Scaffolding

Start by creating a new Nuxt application, or open your existing one.

  1. Initialize your project:

    • Run npx nuxi init my-nuxt-app to create a basic structure.

    • Enter the project folder: cd my-nuxt-app.

    • Install dependencies: npm install.

  2. Add @vue-pdf-viewer:

    • Install the package with npm install @vue-pdf-viewer or yarn add @vue-pdf-viewer.

Here’s a quick checklist before moving ahead:

  • Vue 3

  • Node 16+ for Nuxt 3

With your dependencies set, you’re ready to handle asset organization.

Configure Static Assets for PDF Files

How you store and serve your PDF files matters, especially when it comes to access speed and basic security. Nuxt 3 typically uses the public folder for this job, but there are a few gotchas to keep your files organized and safe.

In Nuxt 3, any files placed in the public folder are served from the root level. For example, a PDF saved as public/sample.pdf will be available at /sample.pdf in your browser.

Best practices for asset management:

  • Organize your PDFs in subfolders (e.g. public/pdfs/) if you plan to store more than a few documents.

  • Keep clear, consistent filenames and avoid spaces, use dashes or underscores.

  • Regularly clean out unused files to keep your build lightweight.

File access security:

Keep in mind that assets in public or static are publicly accessible. If you're dealing with sensitive or private PDFs, don't place them here. Instead:

  • Use authentication and store the files outside public

  • Serve them through a secure API or custom middleware.

Useful Resources

By planning where your PDFs live from the start, you avoid confusion later on—especially as your app grows. Keep things neat and protect anything sensitive, and your PDF workflow in Nuxt will stay smooth and manageable.

Integrating @vue-pdf-viewer in a Nuxt Component

With your Nuxt app set up and PDFs organized, the next step is to actually bring your PDF viewer to life. You have a few key choices here: create a self-contained component for on-demand use, wrap the viewer in client-only rendering to avoid SSR issues, or register it globally for reuse in bigger projects.

Here’s a step-by-step guide to each approach so you choose the one that fits your needs best.

Creating a Reusable PDF Viewer Component

To start, it’s best to build a dedicated Vue component that handles all your PDF viewing logic. This keeps your code tidy and lets you drop the viewer anywhere in your app.

Here’s how you can do it:

  1. Create a new file in your components folder. e.g. PdfViewer.vue

  2. Import @vue-pdf-viewer/viewer and define your props.

  3. Pass in the src prop, which is the path to your PDF file.

  4. Optionally, add viewer options to customize controls or appearance.

Example code: components/PdfViewer.vue

<script setup>
import { ref } from 'vue'
import { VPdfViewer } from '@vue-pdf-viewer/viewer'

const pdfSrc = ref('/pdfs/sample.pdf') // or use a prop for dynamic paths
</script>

<template>
  <v-pdf-viewer :src="pdfSrc" />
</template>

This setup lets you easily update the source PDF or tweak viewer settings as needed. For more details about best practices with Vue components in Nuxt, check out the Nuxt components directory guide.

Client-Side Only Rendering with

Rendering PDF viewers on the server (SSR) can cause headaches since browser-specific APIs don’t exist during server-side rendering. Nuxt provides a simple fix with <ClientOnly> component in Nuxt 3.

How to use it:

In Nuxt 3, Wrap your PDF viewer like this:

<script setup>
import PdfViewer from './components/PdfViewer.vue'
</script>
<template>
 <ClientOnly>
  <PdfViewer />
 </ClientOnly>
</template>

What does this do?

<ClientOnly> tells Nuxt to delay rendering of your PDF viewer component until it's running in the browser. This prevents SSR-related errors from happening when browser-only code is accessed too early.

If you need a deeper explanation or run into issues, check out this discussion on Nuxt client-only plugins.

Using Nuxt Plugins for Global Registration

If your app needs to display PDFs in many places, it helps to register the viewer as a global component. Nuxt’s plugin system makes this smooth and keeps your code DRY (don’t repeat yourself).

Here’s the approach:

  1. Create a new plugin file in plugins/vue-pdf-viewer.js (or .ts).

  2. Import and register @vue-pdf-viewer globally.

  3. In your Nuxt config, make sure the plugin is loaded only on the client.

Example for Nuxt 3:

// plugins/vue-pdf-viewer.client.js
import { defineNuxtPlugin } from '#app'
import { VPdfViewer } from '@vue-pdf-viewer/viewer'

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.component('VPdfViewer', VPdfViewer)
})

Nuxt automatically reads the files in the plugins/ directory and loads them at the creation of the Vue application. For full details, visit the Nuxt plugins directory documentation.

With the viewer globally registered, you can use <VPdfViewer /> anywhere in your project—no manual imports needed. This approach saves you from repetitive imports and keeps your codebase neat as your app scales.


Bonus Section: Styling Your PDF Viewer

Nobody wants a PDF viewer that looks out of place or breaks your app’s design flow. With a little effort, you can easily style @vue-pdf-viewer to match your branding.

Tips for styling:

  • Use CSS for visual tweaks: Adjust background colors, spacing, and toolbar icons by targeting the viewer’s CSS classes. For detailed steps and best practices, check out this resource on customizing CSS in PDF viewers.

  • Use Slots for custom controls: Vue’s slot system makes it easy to insert your own buttons or menus on the toolbar or sidebar.

  • Hide or reorder UI parts: Vue PDF Viewer toolbar can be toggled or reorganized through props or CSS. Keep only what you need on the screen.


Conclusion

Vue PDF Viewer

Launching a PDF viewer in Nuxt with Vue PDF Viewer is fast and hassle-free. You get powerful display options, modern controls, and responsive layouts—ready to go with just a few steps. The component’s flexibility means you can start simple or customize for a tailored user experience.

🙏 Thanks for reading—if you’ve tried this in your own Nuxt app, please feel to share what you built or what you want to see next in Vue PDF Viewer.

I'm looking forward to seeing what you build with Vue PDF Viewer 🚀

0
Subscribe to my newsletter

Read articles from Kittisak Ma directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kittisak Ma
Kittisak Ma