File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 8
8
* e.g. No cross domain requests without CORS.
9
9
*
10
10
* @param {string|TypedAray} source Either a url to a PDF is located or a
11
- * typed array already populated with data.
11
+ * typed array (Uint8Array) already populated with data.
12
+ * @param {Object} headers An object containing the http headers like this:
13
+ * { Authorization: "BASIC XXX" }.
12
14
* @return {Promise} A promise that is resolved with {PDFDocumentProxy} object.
13
15
*/
14
- PDFJS .getDocument = function getDocument (source ) {
16
+ PDFJS .getDocument = function getDocument (source , headers ) {
15
17
var promise = new PDFJS .Promise ();
16
18
var transport = new WorkerTransport (promise );
17
19
if (typeof source === 'string' ) {
@@ -29,7 +31,8 @@ PDFJS.getDocument = function getDocument(source) {
29
31
error : function getPDFError (e ) {
30
32
promise .reject ('Unexpected server response of ' +
31
33
e .target .status + '.' );
32
- }
34
+ },
35
+ headers : headers
33
36
},
34
37
function getPDFLoad (data ) {
35
38
transport .sendData (data );
Original file line number Diff line number Diff line change @@ -31,7 +31,19 @@ function getPdf(arg, callback) {
31
31
params = { url : arg };
32
32
33
33
var xhr = new XMLHttpRequest ();
34
+
34
35
xhr .open ('GET' , params .url );
36
+
37
+ var headers = params .headers ;
38
+ if (headers ) {
39
+ for (var property in headers ) {
40
+ if (typeof headers [property ] === 'undefined' )
41
+ continue ;
42
+
43
+ xhr .setRequestHeader (property , params .headers [property ]);
44
+ }
45
+ }
46
+
35
47
xhr .mozResponseType = xhr .responseType = 'arraybuffer' ;
36
48
var protocol = params .url .indexOf (':' ) < 0 ? window .location .protocol :
37
49
params .url .substring (0 , params .url .indexOf (':' ) + 1 );
You can’t perform that action at this time.
0 commit comments