I have an angular2 project with an ASP.Net Web API. I have code to retrieve a file path from my database which goes to a document on my server. I then want to display this d
Angular 2+ Example PDF-viewer
Page.html
click me to view PDF in Iframe!
PDF in Iframe
PDF in Object Tag
page.ts
import { Component } from '@angular/core';
import { BrowserModule, DomSanitizer, SafeResourceUrl } from '@angular/platform-
browser'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
pdfSrc = 'https://vadimdez.github.io/ng2-pdf-viewer/pdf-test.pdf';
page: number = 1;
pageurl: SafeResourceUrl;
constructor(private domSanitizer: DomSanitizer) {
}
ngOnInit() {
this.pageurl = this.domSanitizer.bypassSecurityTrustResourceUrl(this.pdfSrc);
}
title = 'Mohsen';
}
app.module.ts
add
import { FormsModule } from '@angular/forms';
import { PdfViewerComponent } from 'ng2-pdf-viewer';
import { HttpModule } from '@angular/http';.
import {HttpClientModule} from '@angular/common/http';
import { BrowserModule } from '@angular/platform-browser';
import the
imports: [
BrowserModule,
HttpClientModule,
HttpModule,
FormsModule,
RouterModule.forRoot(appRoutes)
],