ng2-pdfjs-viewer icon indicating copy to clipboard operation
ng2-pdfjs-viewer copied to clipboard

Failure to get PDF from server using JWT

Open estevaocm opened this issue 5 years ago • 3 comments

Hi! I've been trying to use ng2-pdfjs-viewer with a JWT authorization token, with limited success. I am able to download the full file with Angular and passing the blob into ng2-pdfjs-viewer. However, I believe this forces the page to always download the full PDF, while Mozilla's pdfjs can actually download only the requested segments as a default, and this would be ideal for my use case. Of course, I cannot simply pass the URL string without configuring the authorization header. I understand pdfjs also allows for passing a PdfSource object, but this seems to not be working in ng2-pdfjs-viewer.

It is also possible, of course, that I'm doing something wrong. I have also tried accessing PDFViewerApplication directly in order to call the getDocument() function, but it is always undefined for me, within both ngOnInit() and ngAfterViewInit().

Some references I've been following: https://github.com/mozilla/pdf.js/issues/3852 https://stackoverflow.com/questions/51669939/using-pdf-js-viewer-to-display-a-pdf-served-by-a-protected-resource

Thanks in advance.

estevaocm avatar May 27 '20 00:05 estevaocm

Looking into your code, I was under the impression it treats only binary and string inputs, when it converts them to an URI format or somesuch. Perhaps the treatment for objects is missing?

estevaocm avatar May 27 '20 00:05 estevaocm

@estevaocm Will check on this. Do you have a hosted sample?

codehippie1 avatar Jul 27 '20 20:07 codehippie1

Thank you for your consideration. Unfortunately, I cannot at this time provide a hosted sample, due to company policy. I could provide offline code samples, however. At the moment, we are using the inefficient workaround of downloading the entire blob and providing it to ng2-pdfjs-viewer. It would be outstanding to be able to do range downloads on the file.

estevaocm avatar Jul 28 '20 10:07 estevaocm