|
18 | 18 | * @return {Promise} A promise that is resolved with {PDFDocumentProxy} object.
|
19 | 19 | */
|
20 | 20 | PDFJS.getDocument = function getDocument(source) {
|
21 |
| - var url, data, headers, password, parameters = {}, workerInitializedPromise, workerReadyPromise, transport; |
| 21 | + var url, data, headers, password, parameters = {}, workerInitializedPromise, |
| 22 | + workerReadyPromise, transport; |
| 23 | + |
22 | 24 | if (typeof source === 'string') {
|
23 | 25 | url = source;
|
24 | 26 | } else if (isArrayBuffer(source)) {
|
@@ -49,23 +51,27 @@ PDFJS.getDocument = function getDocument(source) {
|
49 | 51 | {
|
50 | 52 | url: url,
|
51 | 53 | progress: function getPDFProgress(evt) {
|
52 |
| - if (evt.lengthComputable) |
53 |
| - workerReadyPromise.progress({ |
| 54 | + if (evt.lengthComputable) { |
| 55 | + workerReadyPromise.progress({ |
54 | 56 | loaded: evt.loaded,
|
55 | 57 | total: evt.total
|
56 | 58 | });
|
| 59 | + } |
57 | 60 | },
|
58 | 61 | error: function getPDFError(e) {
|
59 |
| - workerReadyPromise.reject('Unexpected server response of ' + |
| 62 | + workerReadyPromise.reject('Unexpected server response of ' + |
60 | 63 | e.target.status + '.');
|
61 | 64 | },
|
62 | 65 | headers: headers
|
63 | 66 | },
|
64 | 67 | function getPDFLoad(data) {
|
65 |
| - //we have to wait for the WorkerTransport to finalize worker-support detection! This may take a while... |
66 |
| - workerInitializedPromise.then(function () { |
67 |
| - transport.sendData(data, parameters); |
68 |
| - }); |
| 68 | + // sometimes the pdf has finished downloading before the web worker-test |
| 69 | + // has finished. In that case the rendering of the final pdf would cause |
| 70 | + // errors. We have to wait for the WorkerTransport to finalize worker- |
| 71 | + // support detection |
| 72 | + workerInitializedPromise.then(function workerInitialized() { |
| 73 | + transport.sendData(data, parameters); |
| 74 | + }); |
69 | 75 | });
|
70 | 76 | }
|
71 | 77 |
|
@@ -479,7 +485,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
479 | 485 | // Thus, we fallback to a faked worker.
|
480 | 486 | globalScope.PDFJS.disableWorker = true;
|
481 | 487 | this.setupFakeWorker();
|
482 |
| - workerInitializedPromise.resolve(); |
| 488 | + workerInitializedPromise.resolve(); |
483 | 489 | }
|
484 | 490 | WorkerTransport.prototype = {
|
485 | 491 | destroy: function WorkerTransport_destroy() {
|
|
0 commit comments