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