Add PDF functionality with JavaScript
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.
You can test the SDK capabilities in our playground.
Prefer to jump straight to code? View the example repo on GitHub.
Installation
Reference the Nutrient Web SDK library from your
index.html
file<head>
section:<doctype html><html><head></head><body></body></html>This will load the Nutrient Web SDK from the CDN, allowing you to reference
NutrientViewer
in your JavaScript code.
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(opens in a new tab) 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>Initialize the SDK in JavaScript by calling
window.NutrientViewer.load()
:index.js window.NutrientViewer.load({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 src="index.js"></script>You should now see the PDF rendered in the Nutrient Web SDK UI when you serve the site locally.
<doctype html><html><head></head><body><div id="nutrient" style="width: 100%; height: 100vh;"></div><script src="index.js"></script></body></html>