Nutrient Web SDK is a JavaScript PDF library for viewing, annotating, and editing PDFs directly in the browser. Use it to add PDF capabilities to any web app.
This guide walks you through the steps to integrate Nutrient Web SDK into your project. By the end, you'll be able to render a PDF document in the UI.
Installation
Add the Nutrient Web SDK (
@nutrient-sdk/viewer
) dependency:Terminal window npm i @nutrient-sdk/viewerTerminal window pnpm add @nutrient-sdk/viewerTerminal window yarn add @nutrient-sdk/viewerCopy the SDK assets to the
assets
directory:Terminal window cp -R ./node_modules/@nutrient-sdk/viewer/dist/ ./assets/You're now ready to use the Nutrient Web SDK locally in your NextJS app.
Render a PDF
Rename the PDF document you want to display in your application to document.pdf, and place it in your project’s root directory. You can use this demo document as an example.
Add an empty
<div>
element with a definedwidth
andheight
where the viewer will be mounted:<div id="nutrient" style="width: 100%; height: 100vh;"></div>Import Nutrient Web SDK into your application and initialize the SDK in JavaScript by calling
NutrientViewer.load()
:index.js import "./assets/nutrient-viewer.js";const baseUrl = `${window.location.protocol}//${window.location.host}/assets/`;NutrientViewer.load({baseUrl,container: "#nutrient",document: "document.pdf"}).then(instance => {console.log("Nutrient loaded", instance);}).catch(error => {console.error(error.message);});Import the JavaScript file into your HTML page:
<script type="module" src="index.js"></script>You should see the PDF rendered in the Nutrient Web SDK UI when you serve the site locally.