Merge pull request #8746 from yurydelendik/page-errors

More robust getPage() error handling.
This commit is contained in:
Brendan Dahl 2017-08-04 15:16:50 -07:00 committed by GitHub
commit 1419b7ffe7
4 changed files with 33 additions and 3 deletions

View File

@ -251,6 +251,11 @@ class PDFFindController {
// Store the pageContent as a string. // Store the pageContent as a string.
this.pageContents[i] = strBuf.join(''); this.pageContents[i] = strBuf.join('');
extractTextCapability.resolve(i); extractTextCapability.resolve(i);
}, (reason) => {
console.error(`Unable to get page ${i + 1} text content`, reason);
// Page error -- assuming no text content.
this.pageContents[i] = '';
extractTextCapability.resolve(i);
}); });
}); });
} }

View File

@ -56,6 +56,7 @@ class PDFPageView {
this.id = options.id; this.id = options.id;
this.renderingId = 'page' + this.id; this.renderingId = 'page' + this.id;
this.pdfPage = null;
this.pageLabel = null; this.pageLabel = null;
this.rotation = 0; this.rotation = 0;
this.scale = options.scale || DEFAULT_SCALE; this.scale = options.scale || DEFAULT_SCALE;
@ -110,6 +111,7 @@ class PDFPageView {
this.reset(); this.reset();
if (this.pdfPage) { if (this.pdfPage) {
this.pdfPage.cleanup(); this.pdfPage.cleanup();
this.pdfPage = null;
} }
} }
@ -341,6 +343,11 @@ class PDFPageView {
this.reset(); // Ensure that we reset all state to prevent issues. this.reset(); // Ensure that we reset all state to prevent issues.
} }
if (!this.pdfPage) {
this.renderingState = RenderingStates.FINISHED;
return Promise.reject(new Error('Page is not loaded'));
}
this.renderingState = RenderingStates.RUNNING; this.renderingState = RenderingStates.RUNNING;
let pdfPage = this.pdfPage; let pdfPage = this.pdfPage;

View File

@ -133,10 +133,10 @@ class PDFThumbnailViewer {
this.pdfDocument = pdfDocument; this.pdfDocument = pdfDocument;
if (!pdfDocument) { if (!pdfDocument) {
return Promise.resolve(); return;
} }
return pdfDocument.getPage(1).then((firstPage) => { pdfDocument.getPage(1).then((firstPage) => {
let pagesCount = pdfDocument.numPages; let pagesCount = pdfDocument.numPages;
let viewport = firstPage.getViewport(1.0); let viewport = firstPage.getViewport(1.0);
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) { for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
@ -151,6 +151,8 @@ class PDFThumbnailViewer {
}); });
this._thumbnails.push(thumbnail); this._thumbnails.push(thumbnail);
} }
}).catch((reason) => {
console.error('Unable to initialize thumbnail viewer', reason);
}); });
} }
@ -205,6 +207,10 @@ class PDFThumbnailViewer {
thumbView.setPdfPage(pdfPage); thumbView.setPdfPage(pdfPage);
this._pagesRequests[pageNumber] = null; this._pagesRequests[pageNumber] = null;
return pdfPage; return pdfPage;
}).catch((reason) => {
console.error('Unable to get page for thumb view', reason);
// Page error -- there is nothing can be done.
this._pagesRequests[pageNumber] = null;
}); });
this._pagesRequests[pageNumber] = promise; this._pagesRequests[pageNumber] = promise;
return promise; return promise;

View File

@ -341,7 +341,7 @@ class PDFViewer {
// Fetch a single page so we can get a viewport that will be the default // Fetch a single page so we can get a viewport that will be the default
// viewport for all pages // viewport for all pages
return firstPagePromise.then((pdfPage) => { firstPagePromise.then((pdfPage) => {
let scale = this.currentScale; let scale = this.currentScale;
let viewport = pdfPage.getViewport(scale * CSS_UNITS); let viewport = pdfPage.getViewport(scale * CSS_UNITS);
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) { for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
@ -387,6 +387,12 @@ class PDFViewer {
if (--getPagesLeft === 0) { if (--getPagesLeft === 0) {
pagesCapability.resolve(); pagesCapability.resolve();
} }
}, (reason) => {
console.error(`Unable to get page ${pageNum} to initialize viewer`,
reason);
if (--getPagesLeft === 0) {
pagesCapability.resolve();
}
}); });
} }
}); });
@ -400,6 +406,8 @@ class PDFViewer {
if (this.findController) { if (this.findController) {
this.findController.resolveFirstPage(); this.findController.resolveFirstPage();
} }
}).catch((reason) => {
console.error('Unable to initialize viewer', reason);
}); });
} }
@ -838,6 +846,10 @@ class PDFViewer {
} }
this._pagesRequests[pageNumber] = null; this._pagesRequests[pageNumber] = null;
return pdfPage; return pdfPage;
}).catch((reason) => {
console.error('Unable to get page for page view', reason);
// Page error -- there is nothing can be done.
this._pagesRequests[pageNumber] = null;
}); });
this._pagesRequests[pageNumber] = promise; this._pagesRequests[pageNumber] = promise;
return promise; return promise;