Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Passing arguments to PDFViewerApplication.open #42

Open
oniekrenz opened this issue May 11, 2017 · 2 comments
Open

Passing arguments to PDFViewerApplication.open #42

oniekrenz opened this issue May 11, 2017 · 2 comments

Comments

@oniekrenz
Copy link

Hi,

I needed to load a PDF from a REST API and this failed because the credentials were not sent in the request. I found out that this is possible by passing an argument object with '{ "withCredentials": true }' as the second parameter to PDFViewerApplication.open().
Unfortunately angular-pdfjs-viewer does not support this, so I forked your project and made a quick fix. Maybe you could evaluate if this is a valid approach and can be merged or if you prefer another solution.

@moesjarraf
Copy link
Member

This is precisely the use case when you should use the data attribute, see readme . It should be used whenever the pdf is not publicly available and you need to pass config/headers in the request to get the pdf.

I'd recommend using the $http service to get your pdf, see usage on how to pass in withCredentials to the config.

Example below:

<pdfjs-viewer data="$ctrl.data"></pdfjs-viewer>
$scope.data = null; // this is loaded async

$http.get("http://example.com/my-secure.pdf", {
    responseType: 'arraybuffer',
    withCredentials: true,
    headers: {}
}).then(function (response) {
    $scope.data = new Uint8Array(response.data);
});

@oniekrenz
Copy link
Author

I did consider using the data attribute but as far as I could see there are other arguments you could pass as well. It's not limited to that specific use-case only.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants