Angular 2 how to display .pdf file

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

    If you want do display a base 64 pdf you can use my component https://www.npmjs.com/package/ng2-image-viewer

    It works with angular 2+ and it renders Base 64 images, URL Images and Base 64 PDFs, it's easy to implement, you just have to:

    1) Run npm install ng2-image-viewer --save

    2) Add these codes on your angular-cli.json file:

    "styles": [
         "../node_modules/ng2-image-viewer/imageviewer.scss"
    ],
    "scripts": [
         "../node_modules/ng2-image-viewer/imageviewer.js"
    ],
    

    3) Import ImageViewerModule

    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
    
        // Specify your library as an import
        ImageViewerModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
    

    4) Now you can use it as you wish:

    
    

    Image Viewer

    Here is a demo of it Ng2-Image-Viewer Showcase

    For more info you can check the link above :)

提交回复
热议问题