Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.3K
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!