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/viewerIn the
angular.json
file, add the following to theassets
option:angular.json "assets": ["src/assets",{"glob": "**/*","input": "./node_modules/@nutrient-sdk/viewer/dist/nutrient-viewer-lib/","output": "./assets/nutrient-viewer-lib/"}]Angular will now copy the Nutrient Web SDK assets to the
assets
directory before running your app.
You're now ready to use the Nutrient Web SDK locally in your Angular project.
Render a PDF
Generate a new PDF viewer component:
Terminal window ng generate component pdf-viewerReplace the contents of
src/app/pdf-viewer/pdf-viewer.component.html
with the following:<div class="pdf-viewer"><div id="pspdfkit-container" style="width: 100%; height: 100vh"></div></div>Replace the contents of
src/app/pdf-viewer/pdf-viewer.component.ts
with the following:import { Component, OnInit } from '@angular/core';import NutrientViewer from '@nutrient-sdk/viewer';@Component({selector: 'pdf-viewer',templateUrl: './pdf-viewer.component.html',styleUrls: ['./pdf-viewer.component.css'],standalone: true,})export class PdfViewerComponent implements OnInit {ngOnInit(): void {NutrientViewer.load({// Use the assets directory URL as a base URL. Nutrient will download its library assets from here.baseUrl: `${location.protocol}//${location.host}/assets/`,document: "/assets/document.pdf",container: "#nutrient-container",}).then(instance => {// For the sake of this demo, store the Nutrient for Web instance// on the global object so that you can open the dev tools and// play with the Nutrient API.(window as any).instance = instance;});}}Update the component where you want to use the PDF viewer (for example,
src/app/app.component.ts
) to import thePdfViewerComponent
:import { Component } from '@angular/core';import { RouterOutlet } from '@angular/router';import { PdfViewerComponent } from './pdf-viewer/pdf-viewer.component';@Component({selector: 'app-root',imports: [RouterOutlet, PdfViewerComponent],templateUrl: './app.component.html',styleUrl: './app.component.css'})export class AppComponent {title = 'angular';}Add the
pdf-viewer
to the page where you want to display it (for example,src/app/app.component.html
):<pdf-viewer></pdf-viewer>Start the development server:
Terminal window npm run devTerminal window pnpm run devTerminal window yarn run devYou should see the PDF rendered in the Nutrient Web SDK UI.