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

327
Views
ng2-pdf-viewer issue: 403 when rendering the pdf, even if file is already stored in memory

I'm trying to use ng2 pdf viewer to render a blob that is already saved in memory, but I keep getting a 403 error when trying to render the pdf despite the file being available in memory in a variable (I also have a download button that uses the same variable to download the file locally and that works fine).

This error only happens on our development server. When running my application on localhost everyone is working perfectly fine.

After doing some testing, I seem to have discovered that the pdf viewer module does another backend call to render the PDF, despite the fact that I refer to a variable that holds the file, and this second call is what causes the 403 error. Is this possible?

The chain of events seems to be:

  • My pdf gets loaded through a call to the backend, in the subscribe I put the pdf blob in a file variable
  • the pdf-viewer component is rendered visible since the ng-if is set to true
  • A second call seems to happen to my backend despite the HTML src property referring through an in memory blob. Is this normal behavior or am I minsterpreting what is happening? Can this be avoided? I'm pretty sure this is what is causing my issue.

My typescript method is the following:

downloadFile(observable: Observable<any>) { observable.subscribe((document: any) => { console.log(document) this.file = document; console.log(this.file) if (!this.isFilePdF()) { this.isLoading = false; } }) }

And my HTML is:

<pdf-viewer (error)="logError($event)" [zoom]="zoomRatio" [hidden]="isLoading" *ngIf="isFilePdF()" (after-load-complete)="finishLoading($event)" [(page)]="currentPage" [src]="file" [original-size]="false" [class.height]="!isLoading" style=" width: 100%; background-color:whitesmoke"> </pdf-viewer>

A screenshot of my error: As you see, the first download downloads the file perfectly fine and saves it in the parameter. The second download is causing the error, and I have no idea why the second download is happening since I didn't do anything in my code for it.

As you see, the first download downloads the file perfectly fine and saves it in the parameter. The second download is causing the error, and I have no idea why the second download is happening since I didn't do anything in my code for it.

If there is a way to just use the blob variable from the first download, and not having the second one happen, I'm sure my issue would be resolved.

Does anyone know how to fix the issue I am having?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I was using the latest version ng2-pdf-viewer and the PDF viewer did not work properly.

Then I had to download the ng2-pdf-viewer@^6.2.0 version with its dependencies pdfjs-dist@^2.5.207 version and tslib@^2.0.0 then it worked fine. Make sure the version of dependencies are correct.

I found some references here

about 4 years ago · Juan Pablo Isaza 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!