intbot / ng2-pdfjs-viewer

An angular component for PDFJS and ViewerJS (Supports all versions of angular)
Apache License 2.0
228 stars 112 forks source link

Failure to get PDF from server using JWT #94

Open estevaocm opened 4 years ago

estevaocm commented 4 years ago

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 commented 4 years ago

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?

codehippie1 commented 4 years ago

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

estevaocm commented 4 years ago

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.