Estoy usando la biblioteca ng2-pdf-viewer para Angular y estoy tratando de mostrar un PDF desde una URL básica. el problema es que me sale el siguiente error:
XMLHttpRequest no puede cargarhttps://www.bbv.ch/images/bbv/pdf/Publikationen/BBV16Poster_Angular2.pdf . No hay ningún encabezado 'Access-Control-Allow-Origin' en el recurso solicitado. Por lo tanto, no se permite el acceso al origen ' http://localhost:54800 '.
Aquí está mi código:
.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>Probé con y sin la propiedad "withCredentials", nada cambió.
¿Cómo puedo mostrar cualquier pdf desde un enlace en angular2? (aunque funcionó en un iframe básico...)
Importar estos: -
import { DomSanitizer, SafeResourceUrl, SafeUrl } from '@angular/platform-browser';definir variable: -
Url : SafeUrl;Úselo en un constructor como este-
constructor(private sanitizer: DomSanitizer) {}Especifique una URL como esta-
this.Url = this.sanitizer.bypassSecurityTrustResourceUrl("https://www.bbv.ch/images/bbv/pdf/Publikationen/BBV16Poster_Angular2.pdf");