Skip to content

Commit

Permalink
Allow for the "withCredentials" option to be passed to pdfJS (#257)
Browse files Browse the repository at this point in the history
* Allow for the "withCredentials" option to be passed to pdfJS so that it send cookies

pdfJS uses the "fetch" API to download the PDF. By default, it does not send cookies in cross-site scenarios. With this setting, cookies are always sent.

* Added documentation for options supported by createLoadingTask()

* Send the actual option value, not just "true"
  • Loading branch information
mweimerskirch authored Oct 14, 2020
1 parent ad4d0c2 commit 5273d78
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,18 @@ Triggered when an internal link is clicked

### Public static methods

#### createLoadingTask(src)
#### createLoadingTask(src[, options])
* `src`: see `:src` prop
* `options`: an object of options.
This function creates a PDFJS loading task that can be used and reused as `:src` property.
The loading task is a promise that resolves with the PDFJS pdf document that exposes the `numPages` property (see example below).

**beware:** when the component is destroyed, the object returned by `createLoadingTask()` become invalid.

Supported options:
* onPassword: Callback that's called when a password protected PDF is being opened.
* onProgress: Callback return loading progress.
* withCredentials: Wheter or not to send cookies in the fetch request.


## Examples
Expand Down
3 changes: 3 additions & 0 deletions src/pdfjsWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default function(PDFJS) {
// source.pdfBug = true;
// source.stopAtErrors = true;

if ( options && options.withCredentials )
source.withCredentials = options.withCredentials;

var loadingTask = PDFJS.getDocument(source);
loadingTask.__PDFDocumentLoadingTask = true; // since PDFDocumentLoadingTask is not public

Expand Down

0 comments on commit 5273d78

Please sign in to comment.