---
title: "How to build a JavaScript PDF viewer with Nutrient"
canonical_url: "https://www.nutrient.io/blog/how-to-build-a-javascript-pdf-viewer/"
md_url: "https://www.nutrient.io/blog/how-to-build-a-javascript-pdf-viewer.md"
last_updated: "2026-07-10T06:08:04.774Z"
description: "A step-by-step tutorial explaining how to build a JavaScript PDF viewer with Nutrient PDF viewer."
---

**TL;DR**

Learn how to embed Nutrient’s feature-rich JavaScript PDF viewer into any webpage in five quick steps: install the package, copy the viewer artifacts, add a mount element, call `NutrientViewer.load()`, and serve your page.

## What is a JavaScript PDF viewer?

A [JavaScript PDF viewer](https://www.nutrient.io/sdk/web/) uses JavaScript to render and view PDF documents in a web browser without the need to download it to your hard drive or use an external application like a PDF reader.

## Nutrient JavaScript PDF viewer

We offer a commercial [JavaScript PDF viewer library](https://www.nutrient.io/guides/web/viewer/pdf.md) that can easily be integrated into your web application. It comes with 30+ features that let you view, annotate, edit, and sign documents directly in your browser. Out of the box, it has a polished and flexible UI that you can extend or simplify based on your unique use case.

- A prebuilt and polished UI for an improved user experience

- 15+ prebuilt annotation tools to enable document collaboration

- Support for more file types with client-side [PDF](https://www.nutrient.io/guides/web.md), [MS Office](https://www.nutrient.io/guides/web/viewer/office-documents.md), and [image](https://www.nutrient.io/guides/web/viewer/images.md) viewing

- Dedicated support from engineers to speed up integration

## Example of our JavaScript PDF viewer

To demo our [JavaScript PDF viewer](https://www.nutrient.io/demo/), upload a PDF, JPG, PNG, or TIFF file by clicking Open Document under the Standalone option (if you don’t see this option, select Choose Example from the dropdown). Once your document is displayed in the viewer, try drawing freehand, adding a note, or applying a crop or an eSignature.

If you prefer a video tutorial, you can watch our step-by-step guide.

## Requirements to get started

To get started, you’ll need:

- The [latest stable version of Node.js](https://nodejs.org/en/download/package-manager).

- A package manager compatible with [npm](https://docs.npmjs.com/about-npm). This guide contains usage examples for [Yarn](https://yarnpkg.com/) and the [npm client](https://docs.npmjs.com/cli/v7/commands/npm) (installed with Node.js by default).

## Adding Nutrient to your project

1. Install the `@nutrient-sdk/viewer` package via npm:

   ```bash

   npm install @nutrient-sdk/viewer
   # or

   yarn add @nutrient-sdk/viewer
   # or

   pnpm install @nutrient-sdk/viewer
   ```

2. Copy the required viewer artifacts to your `assets` directory:

   ```bash

   cp -R./node_modules/@nutrient-sdk/viewer/dist/./assets/
   ```

Make sure the `assets` directory contains:

- `nutrient-viewer.js` (or an equivalent main script)

- A `nutrient-viewer-lib/` directory with supporting library files

## Integrating into your project

1. Add the PDF document you want to display to your project’s directory. You can use our [demo document](https://www.nutrient.io/example.pdf) as an example.

2. Add a mounting `<div>` and a script reference to your HTML:

   ```html

   <div id="nutrient" style="width: 100%; height: 100vh;"></div>
   <script type="module" src="index.js"></script>
   ```

3. Import the viewer in your JavaScript entry file:

   ```js

   import "./assets/nutrient-viewer.js";
   ```

4. Initialize the viewer using `NutrientViewer.load()`:

   ```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);
     });
   ```

## Serving your website

1. Install the `serve` package globally:

   ```bash

   npm install --global serve
   ```

2. Start a local server from the current directory:

   ```bash

   serve -l 8080.
   ```

3. Open your browser and go to `http://localhost:8080` to view your website.![nutrient demo](@/assets/images/blog/2021/how-to-build-a-jquery-pdf-viewer-with-pdfjs/pspdfkit-demo.png)

## Adding even more capabilities

Once you’ve deployed your viewer, you can start customizing it to meet your specific requirements or easily add more capabilities. To help you get started, here are some of our most popular JavaScript guides:

- [Adding annotations](https://www.nutrient.io/guides/web/annotations.md)

- [Editing documents](https://www.nutrient.io/guides/web/editor.md)

- [Filling PDF forms](https://www.nutrient.io/guides/web/forms.md)

- [Adding signatures to documents](https://www.nutrient.io/guides/web/signatures.md)

- [Real-time collaboration](https://www.nutrient.io/guides/web/instant-synchronization.md)

- [Redaction](https://www.nutrient.io/guides/web/redaction.md)

- [UI customization](https://www.nutrient.io/guides/web/user-interface.md)

## Conclusion

You should now have our [JavaScript PDF viewer](https://www.nutrient.io/guides/web/viewer/pdf.md) up and running in your web application. If you hit any snags, don’t hesitate to reach out to our [Support team](https://www.nutrient.io/support/request) for help.

You can also integrate our [JavaScript PDF viewer](https://www.nutrient.io/sdk/web/) using web frameworks like [Angular](https://www.nutrient.io/blog/how-to-build-an-angular-pdf-viewer-with-pspdfkit/), [Vue.js](https://www.nutrient.io/blog/how-to-build-a-vuejs-pdf-viewer.md), and [React.js](https://www.nutrient.io/blog/how-to-build-a-reactjs-pdf-viewer.md). To see a list of all web frameworks, start your [free trial](https://www.nutrient.io/try/). Or, [launch our demo](https://www.nutrient.io/demo/) to see our viewer in action.

Do you prefer an open source approach? See how to build a [JavaScript PDF viewer with PDF.js][js-pdfjs].

Comparing libraries before you build? See our roundup of the best [JavaScript PDF viewer][js-viewer-listicle] options.

## FAQ

#### What is Nutrient?

Nutrient is a powerful JavaScript library that allows developers to integrate PDF viewing, editing, and annotation capabilities into web applications.

#### How do I install Nutrient?

You can install Nutrient via npm using the command `npm install @nutrient-sdk/viewer`.

#### Can I use Nutrient with frameworks like React or Angular?

Yes, Nutrient supports integration with various frameworks, including React, Angular, and Vue.js.

#### What file formats does Nutrient support?

Nutrient supports a variety of file formats, including PDF, JPG, PNG, and TIFF.

#### Is there any support available for developers using Nutrient?

Yes, Nutrient offers dedicated support from engineers to assist with integration and troubleshooting.
---

## Related pages

- [Accessibility Untangled Why It Matters Guide](/blog/accessibility-untangled-why-it-matters-guide.md)
- [The business case for accessibility: Five ways it drives enterprise value](/blog/5-ways-accessibility-drives-enterprise-value.md)
- [Advanced Techniques For React Native Ui Components](/blog/advanced-techniques-for-react-native-ui-components.md)
- [Angular File Viewer Pdf Image Office Files](/blog/angular-file-viewer-pdf-image-office-files.md)
- [Ai Document Automation Extraction To Action](/blog/ai-document-automation-extraction-to-action.md)
- [Auto Tagging And Document Accessibility In Dotnet Sdk](/blog/auto-tagging-and-document-accessibility-in-dotnet-sdk.md)
- [Ai Legal Assistant Document Authoring](/blog/ai-legal-assistant-document-authoring.md)
- [The CEO’s AI playbook: Why decision architecture beats model selection](/blog/ceo-ai-playbook-decision-architecture.md)
- [Best Document Viewers](/blog/best-document-viewers.md)
- [Convert One Drive Files To Pdf In Sharepoint](/blog/convert-one-drive-files-to-pdf-in-sharepoint.md)
- [Complete Guide To Pdfjs](/blog/complete-guide-to-pdfjs.md)
- [Construction Document Data Extraction](/blog/construction-document-data-extraction.md)
- [Create And Edit Pdfs In Flutter](/blog/create-and-edit-pdfs-in-flutter.md)
- [Create Pdfs With React](/blog/create-pdfs-with-react.md)
- [Creating A Document Scanner With Ocr In Python](/blog/creating-a-document-scanner-with-ocr-in-python.md)
- [The CTO’s AI playbook: Why accountability architecture beats orchestration](/blog/cto-ai-playbook-accountability-architecture.md)
- [Digital Workflow Automation](/blog/digital-workflow-automation.md)
- [Digital Signatures](/blog/digital-signatures.md)
- [Document Ai Vs Ocr](/blog/document-ai-vs-ocr.md)
- [Document Viewer](/blog/document-viewer.md)
- [app.py](/blog/extract-text-from-pdf-using-python.md)
- [How To Build A Dotnet Maui Pdf Viewer](/blog/how-to-build-a-dotnet-maui-pdf-viewer.md)
- [Emerging threats: Your logging system may be an agentic threat vector](/blog/emerging-threats-your-logging-system.md)
- [How To Build A Flutter Pdf Viewer](/blog/how-to-build-a-flutter-pdf-viewer.md)
- [or](/blog/how-to-build-a-javascript-pdf-viewer-with-pdfjs.md)
- [How To Build A React Powerpoint Viewer](/blog/how-to-build-a-react-powerpoint-viewer.md)
- [or](/blog/how-to-build-a-nextjs-pdf-viewer.md)
- [How To Build A Powerpoint Viewer Using Javascript](/blog/how-to-build-a-powerpoint-viewer-using-javascript.md)
- [How To Build A React Native Pdf Viewer](/blog/how-to-build-a-react-native-pdf-viewer.md)
- [How To Build A Reactjs File Viewer](/blog/how-to-build-a-reactjs-file-viewer.md)
- [Using Yarn](/blog/how-to-build-a-react-excel-viewer.md)
- [or](/blog/how-to-build-a-reactjs-pdf-viewer.md)
- [or](/blog/how-to-build-a-reactjs-pdf-viewer-with-react-pdf.md)
- [How To Build A Vuejs Pdf Viewer With Pdfjs](/blog/how-to-build-a-vuejs-pdf-viewer-with-pdfjs.md)
- [How To Build A Reactjs Viewer With Pdfjs](/blog/how-to-build-a-reactjs-viewer-with-pdfjs.md)
- [How To Build A Vuejs Pdf Viewer](/blog/how-to-build-a-vuejs-pdf-viewer.md)
- [How To Build An Angular Pdf Viewer With Pdfjs](/blog/how-to-build-an-angular-pdf-viewer-with-pdfjs.md)
- [How To Build An Angular Pdf Viewer With Ng2 Pdf Viewer](/blog/how-to-build-an-angular-pdf-viewer-with-ng2-pdf-viewer.md)
- [How To Convert Html To Pdf Using Html2pdf](/blog/how-to-convert-html-to-pdf-using-html2pdf.md)
- [How To Build An Android Pdf Viewer](/blog/how-to-build-an-android-pdf-viewer.md)
- [or](/blog/how-to-convert-html-to-pdf-using-wkhtmltopdf-and-python.md)
- [or](/blog/how-to-convert-html-to-pdf-using-react.md)
- [How To Convert Word To Pdf In Nodejs](/blog/how-to-convert-word-to-pdf-in-nodejs.md)
- [How To Create Pdfs With React To Pdf](/blog/how-to-create-pdfs-with-react-to-pdf.md)
- [How To Edit Pdfs Using Ios Pdf Library](/blog/how-to-edit-pdfs-using-ios-pdf-library.md)
- [How To Embed A Pdf Viewer In Your Website](/blog/how-to-embed-a-pdf-viewer-in-your-website.md)
- [base_url tells WeasyPrint where to resolve relative asset paths](/blog/how-to-generate-pdf-reports-from-html-in-python.md)
- [How To Generate Pdf From Html With Nodejs](/blog/how-to-generate-pdf-from-html-with-nodejs.md)
- [From an HTML string.](/blog/html-in-pdf-format.md)
- [Swift Package Manager](/blog/mobile-pdf-sdk.md)
- [Open an image.](/blog/how-to-use-tesseract-ocr-in-python.md)
- [Linearized Pdf](/blog/linearized-pdf.md)
- [`elements` come from your document parser — each has a type and content.](/blog/multimodal-rag.md)
- [Nutrient Vs Conga Composer](/blog/nutrient-vs-conga-composer.md)
- [Open Pdf In Your Web App](/blog/open-pdf-in-your-web-app.md)
- [Pdf Page Labels](/blog/pdf-page-labels.md)
- [Online Document Viewer](/blog/online-document-viewer.md)
- [Pdf Sdk Performance Benchmark](/blog/pdf-sdk-performance-benchmark.md)
- [Pdfjs Annotation Editor Layer](/blog/pdfjs-annotation-editor-layer.md)
- [Pdf Ua Compliance Guide](/blog/pdf-ua-compliance-guide.md)
- [Pdf Sdk Compliance Security Checklist](/blog/pdf-sdk-compliance-security-checklist.md)
- [Pdfjs Area Annotations Canvas Capture](/blog/pdfjs-area-annotations-canvas-capture.md)
- [Pdfjs Coordinate Systems Pdf To Screen](/blog/pdfjs-coordinate-systems-pdf-to-screen.md)
- [Pdfjs Eventbus Guide](/blog/pdfjs-eventbus-guide.md)
- [Pdfjs Navigation Zoom Rotation](/blog/pdfjs-navigation-zoom-rotation.md)
- [Pdfjs Native Annotation Layer Forms](/blog/pdfjs-native-annotation-layer-forms.md)
- [Pdfjs Pdf Page Manipulation Pdf Lib](/blog/pdfjs-pdf-page-manipulation-pdf-lib.md)
- [Pdfjs Limitations Commercial Upgrade](/blog/pdfjs-limitations-commercial-upgrade.md)
- [Pdfjs Sticky Note Annotations](/blog/pdfjs-sticky-note-annotations.md)
- [Pdfjs React Viewer Setup](/blog/pdfjs-react-viewer-setup.md)
- [Pdfjs Server Side Text Extraction](/blog/pdfjs-server-side-text-extraction.md)
- [Pdfjs Rendering Overlays React Portals](/blog/pdfjs-rendering-overlays-react-portals.md)
- [Pdfjs Thumbnail Sidebar](/blog/pdfjs-thumbnail-sidebar.md)
- [Pdfjs Text Highlight Annotations](/blog/pdfjs-text-highlight-annotations.md)
- [Pdfjs Text Search Pdffindcontroller](/blog/pdfjs-text-search-pdffindcontroller.md)
- [Process Flows](/blog/process-flows.md)
- [or](/blog/sample-blog-updated.md)
- [React Native Pdf Annotation](/blog/react-native-pdf-annotation.md)
- [Open an image file.](/blog/tesseract-python-guide.md)
- [Convert an HTML file to PDF.](/blog/top-ten-ways-to-convert-html-to-pdf.md)
- [Vector Pdf](/blog/vector-pdf.md)
- [Top 5 Javascript Pdf Viewers](/blog/top-5-javascript-pdf-viewers.md)
- [Web Sdk Is Now Headless](/blog/web-sdk-is-now-headless.md)
- [Wcag2 Accessibility Requirements Documents](/blog/wcag2-accessibility-requirements-documents.md)
- [What Is A Vpat](/blog/what-is-a-vpat.md)
- [What Are Annotations](/blog/what-are-annotations.md)
- [Why Your Ai Agent Hallucinates Pdf Table Data](/blog/why-your-ai-agent-hallucinates-pdf-table-data.md)
- [What Is Pdf Ua](/blog/what-is-pdf-ua.md)
- [Why Pdfium Is A Trusted Platform For Pdf Rendering](/blog/why-pdfium-is-a-trusted-platform-for-pdf-rendering.md)

