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 into your project. By the end, you'll be able to render a PDF document in the UI.
Installation
Install Nutrient into your existing Laravel project.
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 Nutrient Web SDK distribution to the
/public/assets/
directory in your project’s folder:Terminal window mkdir public/assets && cp -R ./node_modules/nutrient-sdk/viewer/dist ./public/assets/Make sure your
/public/assets/
directory contains thenutrient-viewer.js
file and anutrient-viewer-lib
directory with the library assets.Make sure your server has the
Content-Type: application/wasm MIME
typeset. Read more about this in the troubleshooting section of our guides.
Render a PDF
Rename the PDF document you want to display in your application to
document.pdf
, and place it in thepublic
directory. You can use this demo document as an example.In
resources/views/welcome.blade.php
, add an empty<div>
element with a definedheight
to where Nutrient will be mounted:<div id="nutrient" style="height: 100vh"></div>Include
nutrient-viewer.js
on thewelcome.blade.php
page:<script src="assets/nutrient-viewer.js"></script>Initialize Nutrient Web SDK in Laravel by calling
NutrientViewer.load()
:<script>NutrientViewer.load({container: "#nutrient",document: "document.pdf" // Add the path to your document here.}).then(function(instance) {console.log("Nutrient loaded", instance);}).catch(function(error) {console.error(error.message);});</script>Run
php artisan serve
. You should see the PDF rendered in the browser.