> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/get-started/libraries-and-frameworks/nuxt.md).

# Build a Nuxt PDF viewer with Apryse WebViewer SDK

Create a Nuxt PDF viewer and editor with Apryse WebViewer. Learn how to integrate the SDK into your NuxtJS apps and render PDFs in the viewer UI.

This guide shows how to build a Nuxt PDF viewer using the Apryse [WebViewer SDK](/web/what-is-webviewer/overview.md). You'll learn how to integrate the SDK into a [Nuxt](https://nuxt.com/docs/4.x/getting-started/introduction) application to render, view, and interact with PDF documents using the WebViewer UI.

You can also download a ready-to-use [GitHub sample](https://github.com/ApryseSDK/webviewer-samples/tree/main/webviewer-nuxtjs) to get started quickly, or explore the interactive [Showcase demo](https://showcase.apryse.com/) to see WebViewer's full capabilities in action.

## Prerequisites

This guide assumes basic familiarity with Nuxt development. Before you start:

* Install [Node.js](https://nodejs.org/en/download) and npm. See the [Nuxt documentation](https://nuxt.com/docs/4.x/getting-started/installation#new-project) for version details.
* Install [Visual Studio Code](https://code.visualstudio.com/Download) or another code editor to develop and debug your code.
* Get your Apryse trial key.

{% @apryse-license-key/apryse-license-key platform="WEB\_VIEWER" variant="full" %}

## 1. Create a Nuxt project

In this section, you’ll create a new Nuxt application using npm. This project provides the foundation for integrating Apryse WebViewer. If you already have a Nuxt app, skip this and continue to [Install WebViewer](#2-install-webviewer).

1. In your terminal, go to the directory where you want to create the project.
2. Create a new `webviewer-nuxt` project using a minimal setup:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```shell
npm create nuxt@latest webviewer-nuxt -y -- --template minimal --packageManager npm --gitInit

```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Info**

Flags are used to skip prompts during project configuration. The setup uses a minimal template, defaults to npm as the package manager, initializes git, and installs dependencies. Select different options if preferred.
{% endhint %}

3. If prompted to install modules, select **No**.
4. Navigate to your new Nuxt project directory and install dependencies:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```shell
cd webviewer-nuxt
npm install
```

{% endcode %}
{% endtab %}
{% endtabs %}

## 2. Install WebViewer

Next, install the Apryse WebViewer SDK using npm. This command adds the [WebViewer package](https://www.npmjs.com/package/@pdftron/webviewer) to your project, allowing you to integrate the PDF viewer and editor into your Nuxt application.

After navigating to your `webviewer-nuxt` project directory, run the following command to install WebViewer:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```shell
npm i @pdftron/webviewer
```

{% endcode %}
{% endtab %}
{% endtabs %}

## 3. Copy WebViewer assets

WebViewer needs access to its static assets at runtime, including WebAssembly modules, HTML, and CSS files. In a Nuxt project, you must copy these assets into the `public` directory so they can be served correctly. For more, see [Copying WebViewer static assets](/web/get-started/copy-assets.md).

1. From your project root, create the `public/lib/webviewer` directory if it doesn't already exist:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```shell
npx --yes shx mkdir -p public/lib/webviewer
```

{% endcode %}
{% endtab %}
{% endtabs %}

2. Copy all WebViewer static assets from `node_modules/@pdftron/webviewer/public` into the new `public/lib/webviewer` directory:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```shell
npx --yes cpy-cli "node_modules/@pdftron/webviewer/public/**/*" public/lib/webviewer
```

{% endcode %}
{% endtab %}
{% endtabs %}

Your project should now include a similar structure:

{% code lineNumbers="true" %}

```
webviewer-nuxt/
├── .nuxt/
├── app/
├── node_modules/
├── public/
│   └── lib/
│       └── webviewer/
│           ├── core/
│           └── ui/
└── favicon.ico
└── ...
```

{% endcode %}

{% hint style="info" %}
**Info**

The `path` option used when initializing WebViewer must point to this directory (for example, `/lib/webviewer`). If the path is incorrect, WebViewer will fail to load.
{% endhint %}

## 4. Create the PDF viewer

In this section, you'll add WebViewer to your Nuxt app by creating a component and initializing the viewer. This mounts the WebViewer UI and loads a document in your application.

1. Create a `components` folder in your project's root:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```shell
npx --yes mkdirp components
```

{% endcode %}
{% endtab %}
{% endtabs %}

2. Create a `WebViewer.vue` file in the `components` folder:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```shell
npx --yes shx touch components/WebViewer.vue
```

{% endcode %}
{% endtab %}
{% endtabs %}

3. In Visual Studio Code, add this code to the `WebViewer.vue` file and save:

<pre class="language-vue" data-line-numbers><code class="lang-vue">&#x3C;template>
  &#x3C;!-- Container element where WebViewer will be mounted -->
  &#x3C;div id="webviewer" ref="viewer">&#x3C;/div>
&#x3C;/template>

&#x3C;script>
// Import APIs and libraries
import { ref, onMounted } from 'vue';
import WebViewer from '@pdftron/webviewer';

export default {
  // Component name for debugging and dev tools
  name: 'WebViewer',
  // Props accepted by the component
  props: {
    initialDoc: { type: String },
  },

  setup(props) {
    // Reference to the DOM element that hosts the viewer
    const viewer = ref(null);

    // Lifecycle hook that runs after the component is mounted to the DOM
    onMounted(() => {
      // Initialize the WebViewer inside the referenced DOM element
      WebViewer(
        {
          // Path to the WebViewer library assets
          path: '/lib/webviewer',
          // Initial document to load into the viewer
          initialDoc: props.initialDoc,
          // License key for Apryse WebViewer
          // Replace with your Apryse license key
          licenseKey: '<code class="expression">visitor.claims.wvKey || "YOUR_LICENSE_KEY"</code>',
        },
        // DOM element where WebViewer is rendered
        viewer.value,
        ).then((instance) => {
          // The WebViewer instance is available here
          // This is where you can customize the UI, register events, etc.
        });
    });

    // Expose refs to the template
    return {
        viewer,
    };
  },
};
&#x3C;/script>

&#x3C;style>
/* Size the WebViewer container */
#webviewer {
  height: 100vh;
  width: 100%;
  margin: 0 auto;
}
&#x3C;/style>
</code></pre>

{% hint style="info" %}
**Info**

If you're signed in with an Apryse account, your license key is automatically prepopulated in all code snippets.
{% endhint %}

4. Replace the contents of the `app/app.vue` file with the following and save:

{% tabs %}
{% tab title="Vue" %}
{% code title="app/app.vue" lineNumbers="true" %}

```vue
<script setup>
import WebViewer from '../components/WebViewer.vue';
</script>

<template>
  <ClientOnly>
    <WebViewer initial-doc="https://apryse.s3.amazonaws.com/public/files/samples/WebviewerDemoDoc.pdf" />
  </ClientOnly>
</template>
```

{% endcode %}
{% endtab %}
{% endtabs %}

## 5. Verify your output

You can now load and display a PDF document in the WebViewer UI. Run your Nuxt application to launch WebViewer and see the PDF in your browser.

1. From your project directory, run the following command to start the application:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```shell
npm run dev
```

{% endcode %}
{% endtab %}
{% endtabs %}

A successful output looks similar to:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```shell
> dev
> nuxt dev

●  Nuxt 4.4.7 (with Nitro 2.13.4, Vite 7.3.5 and Vue 3.5.35)

  ➜ Local:    http://localhost:3000/
  ➜ Network:  use --host to expose

  ➜ DevTools: press Shift + Option + D in the browser (v3.2.4)

✔ Vite client built in 32ms
✔ Vite server built in 9ms
```

{% endcode %}
{% endtab %}
{% endtabs %}

2. Open the localhost URL from your terminal to view the WebViewer UI and PDF document.

## Get started video

In this 5-minute video, learn how to install and integrate the Apryse WebViewer SDK into a Nuxt project. You’ll set up the PDF viewer, verify it’s working in the UI, and then enable the Apryse Spreadsheet Editor.

{% embed url="<https://www.youtube.com/embed/UOKDUNYw_gk?si=Ad-nN-L6olaWQrZ5>" %}
Integrate WebViewer into a Nuxt project and enable the Spreadsheet Editor.
{% endembed %}

## Next steps

<a href="/web/what-is-webviewer/usage.md" class="button primary">Usage</a><a href="/web/get-started/guides.md" class="button primary">Guides</a><a href="/web/get-started/samples.md" class="button primary">Samples</a><a href="https://sdk.apryse.com/api/web/index.html" class="button primary">API docs</a>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/web/get-started/libraries-and-frameworks/nuxt.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
