Thursday, August 28, 2025
HomeLanguagesAngularCreate PDF Viewer in Angular 12/11 using Ng2-pdf Viewer

Create PDF Viewer in Angular 12/11 using Ng2-pdf Viewer

Angular 11/12 pdf viewer example. In this tutorial, you will learn how to create a pdf viewer in the angular 11/12 app using ng2-pdf-viewer npm Package.

This tutorial will help you step by step on how to create pdf viewer in angular 11/12 app using ng2-pdf-viewer npm package. And easy install and use ng2-pdf-viewer npm package in this app.

PDF Viewer in Angular 12/11 Example

  • Step 1 – Create New Angular App
  • Step 2 – Install ng2-pdf-viewer npm Package
  • Step 3 – Add Code on Module.ts File
  • Step 4 – Add Code on View File
  • Step 5 – Add Code On Component ts File
  • Step 6 – Start Angular App

Step 1 – Create New Angular App

First of all, open your terminal and execute the following command on it to install angular app:

ng new my-new-app

Step 2 – Install ng2-pdf-viewer npm Package

In this step, you need to install ng2-pdf-viewer npm Package in our angular application. So, open your terminal and execute the following command:

npm install ng2-pdf-viewer

Step 3 – Add Code on Module.ts File

In this step, you need to import pdf viewer module. So, visit src/app directory and open app.module.ts file. Then add the following code into it:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
  
import { AppComponent } from './app.component';
import { PdfViewerModule } from 'ng2-pdf-viewer';
  
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    PdfViewerModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Step 4 – Add Code on View File

In this step, create html and for display pdf viewer in angular 11 ap. So, visit src/app/app.component.html and update the following code into it:

<h1>Angular 11/10 PDF File Viewer Example - Tutsmake.com</h1>
  
<pdf-viewer [src]="pdfFilePath" 
              [render-text]="true"
              style="display: block;"
  ></pdf-viewer>

Step 5 – Add Code On Component ts File

In this step, visit the src/app directory and open app.component.ts. Then add the following code into component.ts file:

import { Component } from '@angular/core';
  
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
    pdfFilePath = "https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf";
}

Step 6 – Start Angular App

In this step, execute the following commands on terminal to start angular app:

ng serve

Recommended Angular Posts

RELATED ARTICLES

Most Popular

Dominic
32244 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6615 POSTS0 COMMENTS
Nicole Veronica
11787 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11831 POSTS0 COMMENTS
Shaida Kate Naidoo
6726 POSTS0 COMMENTS
Ted Musemwa
7008 POSTS0 COMMENTS
Thapelo Manthata
6683 POSTS0 COMMENTS
Umr Jansen
6696 POSTS0 COMMENTS