Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.3K
Vistas
ng2-pdf-viewer Access-Control-Allow-Origin

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...)

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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");
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda