Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.3K
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda