This guide will show you how to integrate WebViewer Document Viewer & Editor into a Next.js 14 application. WebViewer works with other versions of Next.js, but you may need to tweak the code slightly.
You can also download a ready-to-go sample on GitHub.
Prior to starting, you should have already installed Node and npm.
Get your Apryse trial key.
Apryse collects some data regarding your usage of the SDK for product improvement.
If you wish to continue without data collection, contact us and we will email you a no-tracking trial key for you to get started.
This video teaches you the fundamentals of installing and initializing WebViewer in any web application. If you wish, you may skip this section and proceed to the steps below.
If you already have a Next.js project set up, skip to step 2.
We will use create-next-app
to scaffold our project. To get started, run the following command:
You may be asked if you want to install the create-next-app
package. In this case, select yes.
Next you will be asked to name your project. You can choose whatever name you wish.
You will now be asked to select which features to include in your project. For this step, you may also choose whatever you wish - your choices will not impact the rest of the steps.
Now, we can install WebViewer by running the following command.
We also have to copy the static assets required for WebViewer to run. The files are located in node_modules/@pdftron/webviewer/public
and must be moved into a location that will be served and publicly accessible. In Next.js, it will be public
folder.
In package.json
we will add a command that copies these static assets to our public
folder.
package.json
You'll notice that we also updated our other scripts to run this command first - this is recommended to make sure your WebViewer assets are always in the right place.
Read more about copying static assets.
Next, we can build our WebViewer component.
Create a file called components/WebViewer.jsx
and add the following code:
components/WebViewer.jsx
Then, we can import our component and use it elsewhere in our app.
page.jsx
Now run the app by running npm run dev
. You should see WebViewer mounted with a default document loaded.
You can now checkout other guides like how to open your own documents or how to disable certain features.
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales