Module Configuration
Configuration
Add the kviewer key to your nuxt.config.ts:
export default defineNuxtConfig({
modules: ['kviewer'],
kviewer: {
prefix: 'K',
},
})
Options
| Option | Type | Default | Description |
|---|---|---|---|
prefix | string | '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. |
assetsBaseURL | string | '/_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:
| Prefix | Viewer | Tabs |
|---|---|---|
'K' (default) | KViewer | KViewerTabs |
'Pdf' | PdfViewer | PdfViewerTabs |
'My' | MyViewer | MyViewerTabs |
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:
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
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:
<template>
<ClientOnly fallback-tag="div" fallback="Loading viewer...">
<KViewer source="/sample.pdf" />
</ClientOnly>
</template>
Disable SSR per page
<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 layerkviewer.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:
KViewer-- Single document viewer (API reference)KViewerTabs-- Multi-document tabbed viewer (API reference)