From 0b0bf71ad0148ed6225f382cb97f6890c1abee09 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 19 Nov 2019 11:58:19 +0100 Subject: [PATCH] Ensure that attempting to print with `disableAutoFetch` set will fail gracefully (issue 11339) This patch simply restores the behaviour that existed prior to PR 7697, since I cannot imagine that that was changed other than by pure accident. As mentioned by a comment in `BaseViewer.setDocument`: "Printing is semi-broken with auto fetch disabled.", and note that since triggering of printing is a synchronous operation there's generally no easy way to load the missing data. https://github.com/mozilla/pdf.js/pull/7697/files#diff-529d1853ee1bba753a0fcb40ea778723L1114-L1118 --- web/base_viewer.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/web/base_viewer.js b/web/base_viewer.js index ddb7c0b26..6b90f12bf 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -181,7 +181,14 @@ class BaseViewer { * @type {boolean} - True if all {PDFPageView} objects are initialized. */ get pageViewsReady() { - return this._pageViewsReady; + if (!this._pageViewsReady) { + return false; + } + // Prevent printing errors when 'disableAutoFetch' is set, by ensuring + // that *all* pages have in fact been completely loaded. + return this._pages.every(function(pageView) { + return !!(pageView && pageView.pdfPage); + }); } /**