Angular 2 how to display .pdf file

后端 未结 9 519
不知归路
不知归路 2020-12-18 18:01

I have an angular2 app, where I want the user to be able to download and open a pdf file in the browser.

Is there an angular2 module or component that I can use?

9条回答
  •  太阳男子
    2020-12-18 18:37

    If you want PDF viewer with a classy toolbar, then use ngx-extended-pdf-viewer. It has all needed options such as print, download, page navigation etc.

    How to use the library:

    1. Install the library with npm i ngx-extended-pdf-viewer --save
    2. Add following scripts to your angular.json

      "scripts": [ "node_modules/ngx-extended-pdf-viewer/assets/pdf.js", "node_modules/ngx-extended-pdf-viewer/assets/pdf.worker.js", "node_modules/ngx-extended-pdf-viewer/assets/viewer.js" ]

    3. Add "NgxExtendedPdfViewerModule" to the import section of your module file

    4. Display it in your component like this:

提交回复
热议问题