How to build an Angular PDF viewer

How to build an Angular PDF viewer

In this post, we provide you with a step-by-step guide on how you can deploy Nutrient’s Angular PDF viewer. Angular is a TypeScript web application framework developed by Google, and according to the Stack Overflow 2021 Developer Survey(opens in a new tab), it’s the web’s third-most popular framework.

What is an Angular PDF viewer?

An Angular PDF viewer lets you 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 Web SDK

We offer a commercial Angular PDF viewer library 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 UI — Save time with a well-documented list of APIs when customizing the UI to meet your exact requirements.
  • Annotation tools — Draw, circle, highlight, comment, and add notes to documents with 15+ prebuilt annotation tools.
  • Multiple file types — Support client-side viewing of PDFs, MS Office documents, and image files.
  • 30+ features — Easily add features like PDF editing, digital signatures, form filling, real-time document collaboration, and more.
  • Dedicated support — Deploy faster by working 1-on-1 with our developers.

Example of our Angular PDF viewer

To demo our Angular PDF viewer, 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.

Requirements to get started

To get started, you’ll need:

When you install Node.js, npm is installed by default.

Setup

Go to your terminal and install the Angular CLI(opens in a new tab). This will help you get up and running quickly with Angular:

npm install -g @angular/cli
yarn global add @angular/cli

Now, you can check the version of Angular:

Terminal window
ng --version

Add PDF functionality with Angular using Nutrient Web SDK

Nutrient Web SDK is a fast, flexible JavaScript library for rendering and interacting with PDFs entirely in the browser. It requires no server-side rendering and includes features like form filling, dark mode, bookmarks, and responsive design.

Follow the steps below to integrate Nutrient into your Angular app and build a fully functional PDF viewer.

Step 1 — Install the Nutrient viewer

Install the SDK package using your preferred package manager:

Terminal window
npm install @nutrient-sdk/viewer

Then, configure Angular to copy the SDK’s required assets at build time. Open your angular.json file and add this to the assets array:

"assets": [
"src/assets",
{
"glob": "**/*",
"input": "./node_modules/@nutrient-sdk/viewer/dist/nutrient-viewer-lib/",
"output": "./assets/nutrient-viewer-lib/"
}
]

This ensures Nutrient’s JavaScript and WebAssembly files are bundled into your app so the SDK can load them when the viewer runs.

Step 2 — Create and configure the PDF viewer

  1. Use Angular CLI to create a new component:
Terminal window
ng generate component pdf-viewer

This creates the component’s HTML, TypeScript, and CSS files in src/app/pdf-viewer.

  1. In pdf-viewer.component.html, add a container where the viewer will mount:
<div class="pdf-viewer">
<div id="nutrient-container" style="width: 100%; height: 100vh"></div>
</div>

The #nutrient-container div is where the SDK will render the PDF viewer UI.

Load and render the PDF

In pdf-viewer.component.ts, initialize the SDK:

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({
// The SDK loads viewer assets from this base URL.
baseUrl: `${location.protocol}//${location.host}/assets/`,
// PDF document to load.
document: "/assets/document.pdf",
// DOM container where the viewer should be rendered.
container: "#nutrient-container",
}).then((instance) => {
// Optional: expose viewer instance for debugging.
(window as any).instance = instance;
});
}
}

Add a sample PDF to the src/assets folder and name it document.pdf, or use any PDF file you want to display. Nutrient Web SDK will automatically load this file when the viewer initializes.

Step 3 — Display the viewer in your app

To make the viewer appear, import and use the PdfViewerComponent in your root component.

In app.component.ts:

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",
styleUrls: ["./app.component.css"],
})
export class AppComponent {
title = "angular";
}

In app.component.html:

<pdf-viewer></pdf-viewer>

This mounts your PDF viewer on the page using Angular’s component system.

Step 4 — Run the application

Start your Angular app with:

Terminal window
npm run dev

Navigate to http://localhost:4200 and you’ll see your PDF rendered inside the Nutrient viewer. The UI includes zoom, navigation, full-text search, annotation tools, and more — all ready to use.

You can access the project on GitHub(opens in a new tab).

Video poster

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 Angular guides:

Conclusion

You should now have our Angular PDF viewer up and running in your web application. If you hit any snags, don’t hesitate to reach out to our Support team for help.

You can also deploy our vanilla JavaScript PDF viewer or use one of our many web framework deployment options like Vue.js, React.js, and jQuery. To see a list of all web frameworks, start your free trial. Or, launch our demo to see our viewer in action.

Hulya Masharipov

Hulya Masharipov

Technical Writer

Hulya is a frontend web developer and technical writer at Nutrient who enjoys creating responsive, scalable, and maintainable web experiences. She’s passionate about open source, web accessibility, cybersecurity privacy, and blockchain.

Explore related topics

FREE TRIAL Ready to get started?