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