Angular 2 how to display .pdf file

后端 未结 9 536
不知归路
不知归路 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:35

    Try ng2-pdfjs-viewer (https://www.npmjs.com/package/ng2-pdfjs-viewer). IMHO, it proved to be the easiest and most reliable to use so far - while building a pdf intense application. You get a full figure viewer and a lot of additional functionalities - print preview, auto download, open in new tab, zoom, scroll, go to page/named destination, rotate document etc. It works with pdf streams and physical pdf files alike. If you are building around serving pdf through web browser on angular; this package is of great help.

    1. Install it
      $ npm install ng2-pdfjs-viewer --save

    2. Add to app module

    import { PdfJsViewerModule } from 'ng2-pdfjs-viewer'; // <-- Import PdfJsViewerModule module
    
    @NgModule({
      imports: [
        PdfJsViewerModule // <-- Add to declarations
      ],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
    
    1. Use it.

提交回复
热议问题