I am using the ng2-pdf-viewer library for Angular and I am trying to display a PDF from a basic url. the problem is I get the following error :
XMLHttpRequest cannot load https://www.bbv.ch/images/bbv/pdf/Publikationen/BBV16Poster_Angular2.pdf. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:54800' is therefore not allowed access.
Here is my code :
.ts :
{ Name: "Angular2 tuto", Description: "An amazing Angular2 pdf !", Url: {url: "https://www.bbv.ch/images/bbv/pdf/Publikationen/BBV16Poster_Angular2.pdf", withCredentials: true} }
.html :
<pdf-viewer [src]="document.Url" [page]="1" [original-size]="false" style="display: block;"></pdf-viewer>
I tried with and without "withCredentials" property - nothing changed..
How can I show any pdf from a link in angular2 ? (worked in a basic iframe though...)
Import these :-
import { DomSanitizer, SafeResourceUrl, SafeUrl } from '@angular/platform-browser';
define variable :-
Url : SafeUrl;
Use it in constructor like this-
constructor(private sanitizer: DomSanitizer) {}
Specifiy URL like this-
this.Url = this.sanitizer.bypassSecurityTrustResourceUrl("https://www.bbv.ch/images/bbv/pdf/Publikationen/BBV16Poster_Angular2.pdf");