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 user interface (UI).

CDN installation

Note: Creating a new project (optional)

If you don’t yet have a PHP project set up, create a new folder with an index.php file and run:

Terminal window
php -S 127.0.0.1:8000
  1. To use Nutrient Viewer in your PHP project, include the following in your page to load the library from the CDN:

    <script src="https://cdn.cloud.nutrient.io/pspdfkit-web@1.13.0/nutrient-viewer.js"></script>

    This will make the NutrientViewer object available globally in your page so you can initialize the viewer later.

Rendering a PDF

  1. Add an empty <div> element with a defined width and height where Nutrient will be mounted:

    <div id="nutrient" style="width: 100%; height: 100vh;"></div>
  2. Add the following script to initialize the Nutrient Viewer:

    <script>
    NutrientViewer.load({
    container: "#nutrient",
    document: "https://www.nutrient.io/downloads/nutrient-web-demo.pdf"
    })
    .then(function(instance) {
    console.log("Nutrient loaded", instance);
    })
    .catch(function(error) {
    console.error(error.message);
    });
    </script>
  3. Here’s the full example of a complete index.php file you can use:

    <!DOCTYPE html>
    <html>
    <head>
    <title>My App</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    </head>
    <body>
    <div id="nutrient" style="width: 100%; height: 100vh;"></div>
    <script src="https://cdn.cloud.nutrient.io/pspdfkit-web@1.13.0/nutrient-viewer.js"></script>
    <script>
    NutrientViewer.load({
    container: "#nutrient",
    document: "https://www.nutrient.io/downloads/nutrient-web-demo.pdf",
    })
    .then(function (instance) {
    console.log("Nutrient loaded", instance);
    })
    .catch(function (error) {
    console.error("Failed to load Nutrient:", error.message);
    });
    </script>
    </body>
    </html>
  4. Start your PHP server:

    Terminal window
    php -S 127.0.0.1:8000
  5. Visit http://127.0.0.1:8000/index.php in your browser.

For a full walkthrough, refer to our PHP PDF viewer tutorial.

Optimizing load performance

If your app doesn’t open a PDF immediately — for example, the user navigates to a viewer on a different page — call NutrientViewer.preloadWorker() early in your app to fetch and compile the WebAssembly artifacts in the background. When NutrientViewer.load() runs later, it can start rendering without waiting for them.

// Call early — for example, on app init or after login.
NutrientViewer.preloadWorker();

Refer to the performance best practices guide for more optimization techniques.

Troubleshooting