9951 explained code solutions for 126 technologies


angularjsHow can I add a PDF viewer to my AngularJS application?


To add a PDF viewer to an AngularJS application, you can use the ng2-pdf-viewer library. This library provides an Angular component that wraps the PDF.js library.

To install this library, you can use npm:

npm install ng2-pdf-viewer

Once installed, you can use the PdfViewerComponent component in your application. For example, you can add the following code to your template:

<pdf-viewer [src]="pdfSrc"></pdf-viewer>

In your component, you can provide the pdfSrc property with the path to your PDF file, like this:

export class AppComponent {
  pdfSrc: string = '/assets/sample.pdf';
}

The PdfViewerComponent also provides a number of options that you can use to customize the viewer.

Helpful links

Edit this code on GitHub