kviewer
API

Module Configuration

Configure the KViewer Nuxt module

Configuration

Add the kviewer key to your nuxt.config.ts:

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['kviewer'],
  kviewer: {
    prefix: 'K',
  },
})

Options

OptionTypeDefaultDescription
prefixstring'K'Prefix for auto-registered component names
locale'en' | 'de' | 'fr' | 'nl''en'Default UI language for built-in viewer strings. The KViewer locale prop overrides it per instance.
assetsBaseURLstring'/_kviewer/'URL the browser loads pdf.js's data files from. Only needed when the app runs below a sub-path; see Asset URLs.

Component Prefix

The prefix option controls how components are registered:

PrefixViewerTabs
'K' (default)KViewerKViewerTabs
'Pdf'PdfViewerPdfViewerTabs
'My'MyViewerMyViewerTabs

Asset URLs

pdf.js loads data files at runtime: the standard 14 fonts, CMaps, wasm decoders (JPEG2000, JBIG2, ICC colour), a CMYK profile and, with scripting, the QuickJS sandbox. The module serves them as Nitro public assets, which Nitro places below your app.baseURL (<app.baseURL>_kviewer/).

By default the viewer requests them at /_kviewer/, which is correct for apps served at the root. If your app runs below a sub-path, point the viewer at the prefixed location:

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['kviewer'],
  app: { baseURL: '/foo/' },
  kviewer: {
    assetsBaseURL: '/foo/_kviewer/',
  },
})

The value is public runtime config, so a deployment can also override it without a rebuild via NUXT_PUBLIC_KVIEWER_ASSETS_BASE_URL. A full URL (for example a CDN that mirrors the files) works as well.

Without it, a sub-path app requests /_kviewer/... outside the app. pdf.js then falls back silently: generic fonts instead of the standard fonts, missing CJK text, and blank JPEG2000/JBIG2 images.

Client-Side Rendering

KViewer components depend on browser APIs (Canvas, DOM) through pdfjs-dist and Konva. They cannot render on the server. You have three options:

Disable SSR globally

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['kviewer'],
  ssr: false,
})

Use <ClientOnly>

Wrap the viewer to skip server rendering while keeping SSR for the rest of your app:

pages/viewer.vue
<template>
  <ClientOnly fallback-tag="div" fallback="Loading viewer...">
    <KViewer source="/sample.pdf" />
  </ClientOnly>
</template>

Disable SSR per page

pages/viewer.vue
<script setup lang="ts">
definePageMeta({
  ssr: false,
})
</script>

<template>
  <KViewer source="/sample.pdf" />
</template>

Auto-Imported CSS

The module automatically injects these CSS files:

  • pdfjs-dist/web/pdf_viewer.css -- Styles for the text selection layer
  • kviewer.css -- Cursor styles for annotation tools

No manual CSS imports are needed.

Auto-Imported Components

All KViewer components are auto-imported with the configured prefix. The main components you'll use are:

Copyright © 2026