Move the disableAutoFetch
option from the global PDFJS
object and into getDocument
instead
One additional complication with removing this option from the global `PDFJS` object, is that the viewer currently needs to check `disableAutoFetch` in a couple of places. To address this I'm thus proposing adding a getter in `PDFDocumentProxy`, to allow checking the *actually* used values for a particular `getDocument` invocation.
This commit is contained in:
parent
c7c583583b
commit
69d7191034
@ -18,7 +18,7 @@ import {
|
|||||||
assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException,
|
assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException,
|
||||||
isArrayBuffer, isNum, isSameOrigin, MessageHandler, MissingPDFException,
|
isArrayBuffer, isNum, isSameOrigin, MessageHandler, MissingPDFException,
|
||||||
NativeImageDecoding, PageViewport, PasswordException, setVerbosityLevel,
|
NativeImageDecoding, PageViewport, PasswordException, setVerbosityLevel,
|
||||||
stringToBytes, UnexpectedResponseException, UnknownErrorException,
|
shadow, stringToBytes, UnexpectedResponseException, UnknownErrorException,
|
||||||
unreachable, Util, warn
|
unreachable, Util, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import {
|
import {
|
||||||
@ -164,6 +164,12 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
|
|||||||
* converted to OpenType fonts and loaded via font face rules. If disabled,
|
* converted to OpenType fonts and loaded via font face rules. If disabled,
|
||||||
* fonts will be rendered using a built-in font renderer that constructs the
|
* fonts will be rendered using a built-in font renderer that constructs the
|
||||||
* glyphs with primitive path commands. The default value is `false`.
|
* glyphs with primitive path commands. The default value is `false`.
|
||||||
|
* @property {boolean} disableAutoFetch - (optional) Disable pre-fetching of PDF
|
||||||
|
* file data. When range requests are enabled PDF.js will automatically keep
|
||||||
|
* fetching more data even if it isn't needed to display the current page.
|
||||||
|
* The default value is `false`.
|
||||||
|
* NOTE: It is also necessary to disable streaming, see above,
|
||||||
|
* in order for disabling of pre-fetching to work correctly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -266,6 +272,10 @@ function getDocument(src) {
|
|||||||
params.disableFontFace = false;
|
params.disableFontFace = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof params.disableAutoFetch !== 'boolean') {
|
||||||
|
params.disableAutoFetch = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Set the main-thread verbosity level.
|
// Set the main-thread verbosity level.
|
||||||
setVerbosityLevel(params.verbosity);
|
setVerbosityLevel(params.verbosity);
|
||||||
|
|
||||||
@ -333,7 +343,6 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
|
|||||||
typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_VERSION') : null;
|
typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_VERSION') : null;
|
||||||
|
|
||||||
source.disableRange = getDefaultSetting('disableRange');
|
source.disableRange = getDefaultSetting('disableRange');
|
||||||
source.disableAutoFetch = getDefaultSetting('disableAutoFetch');
|
|
||||||
source.disableStream = getDefaultSetting('disableStream');
|
source.disableStream = getDefaultSetting('disableStream');
|
||||||
if (pdfDataRangeTransport) {
|
if (pdfDataRangeTransport) {
|
||||||
source.length = pdfDataRangeTransport.length;
|
source.length = pdfDataRangeTransport.length;
|
||||||
@ -683,6 +692,10 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
|||||||
destroy: function PDFDocumentProxy_destroy() {
|
destroy: function PDFDocumentProxy_destroy() {
|
||||||
return this.loadingTask.destroy();
|
return this.loadingTask.destroy();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get loadingParams() {
|
||||||
|
return this.transport.loadingParams;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
return PDFDocumentProxy;
|
return PDFDocumentProxy;
|
||||||
})();
|
})();
|
||||||
@ -2116,6 +2129,13 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
this.fontLoader.clear();
|
this.fontLoader.clear();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get loadingParams() {
|
||||||
|
let params = this._params;
|
||||||
|
return shadow(this, 'loadingParams', {
|
||||||
|
disableAutoFetch: params.disableAutoFetch,
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
return WorkerTransport;
|
return WorkerTransport;
|
||||||
|
|
||||||
|
@ -336,8 +336,6 @@ function getDefaultSetting(id) {
|
|||||||
switch (id) {
|
switch (id) {
|
||||||
case 'pdfBug':
|
case 'pdfBug':
|
||||||
return globalSettings ? globalSettings.pdfBug : false;
|
return globalSettings ? globalSettings.pdfBug : false;
|
||||||
case 'disableAutoFetch':
|
|
||||||
return globalSettings ? globalSettings.disableAutoFetch : false;
|
|
||||||
case 'disableStream':
|
case 'disableStream':
|
||||||
return globalSettings ? globalSettings.disableStream : false;
|
return globalSettings ? globalSettings.disableStream : false;
|
||||||
case 'disableRange':
|
case 'disableRange':
|
||||||
|
@ -82,18 +82,6 @@ PDFJS.disableRange = (PDFJS.disableRange === undefined ?
|
|||||||
PDFJS.disableStream = (PDFJS.disableStream === undefined ?
|
PDFJS.disableStream = (PDFJS.disableStream === undefined ?
|
||||||
false : PDFJS.disableStream);
|
false : PDFJS.disableStream);
|
||||||
|
|
||||||
/**
|
|
||||||
* Disable pre-fetching of PDF file data. When range requests are enabled
|
|
||||||
* PDF.js will automatically keep fetching more data even if it isn't needed
|
|
||||||
* to display the current page. This default behavior can be disabled.
|
|
||||||
*
|
|
||||||
* NOTE: It is also necessary to disable streaming, see above,
|
|
||||||
* in order for disabling of pre-fetching to work correctly.
|
|
||||||
* @var {boolean}
|
|
||||||
*/
|
|
||||||
PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
|
|
||||||
false : PDFJS.disableAutoFetch);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables special hooks for debugging PDF.js.
|
* Enables special hooks for debugging PDF.js.
|
||||||
* @var {boolean}
|
* @var {boolean}
|
||||||
|
@ -360,7 +360,6 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
|
|||||||
|
|
||||||
let absoluteUrl = new URL(task.file, window.location).href;
|
let absoluteUrl = new URL(task.file, window.location).href;
|
||||||
PDFJS.disableRange = task.disableRange;
|
PDFJS.disableRange = task.disableRange;
|
||||||
PDFJS.disableAutoFetch = !task.enableAutoFetch;
|
|
||||||
try {
|
try {
|
||||||
PDFJS.getDocument({
|
PDFJS.getDocument({
|
||||||
url: absoluteUrl,
|
url: absoluteUrl,
|
||||||
@ -368,6 +367,7 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
|
|||||||
nativeImageDecoderSupport: task.nativeImageDecoderSupport,
|
nativeImageDecoderSupport: task.nativeImageDecoderSupport,
|
||||||
cMapUrl: CMAP_URL,
|
cMapUrl: CMAP_URL,
|
||||||
cMapPacked: CMAP_PACKED,
|
cMapPacked: CMAP_PACKED,
|
||||||
|
disableAutoFetch: !task.enableAutoFetch,
|
||||||
}).then((doc) => {
|
}).then((doc) => {
|
||||||
task.pdfDoc = doc;
|
task.pdfDoc = doc;
|
||||||
this._nextPage(task, failure);
|
this._nextPage(task, failure);
|
||||||
|
11
web/app.js
11
web/app.js
@ -207,7 +207,7 @@ let PDFViewerApplication = {
|
|||||||
PDFJS.disableStream = value;
|
PDFJS.disableStream = value;
|
||||||
}),
|
}),
|
||||||
preferences.get('disableAutoFetch').then(function resolved(value) {
|
preferences.get('disableAutoFetch').then(function resolved(value) {
|
||||||
PDFJS.disableAutoFetch = value;
|
AppOptions.set('disableAutoFetch', value);
|
||||||
}),
|
}),
|
||||||
preferences.get('disableFontFace').then(function resolved(value) {
|
preferences.get('disableFontFace').then(function resolved(value) {
|
||||||
if (AppOptions.get('disableFontFace') === true) {
|
if (AppOptions.get('disableFontFace') === true) {
|
||||||
@ -266,7 +266,8 @@ let PDFViewerApplication = {
|
|||||||
PDFJS.disableStream = (hashParams['disablestream'] === 'true');
|
PDFJS.disableStream = (hashParams['disablestream'] === 'true');
|
||||||
}
|
}
|
||||||
if ('disableautofetch' in hashParams) {
|
if ('disableautofetch' in hashParams) {
|
||||||
PDFJS.disableAutoFetch = (hashParams['disableautofetch'] === 'true');
|
AppOptions.set('disableAutoFetch',
|
||||||
|
hashParams['disableautofetch'] === 'true');
|
||||||
}
|
}
|
||||||
if ('disablefontface' in hashParams) {
|
if ('disablefontface' in hashParams) {
|
||||||
AppOptions.set('disableFontFace',
|
AppOptions.set('disableFontFace',
|
||||||
@ -933,7 +934,11 @@ let PDFViewerApplication = {
|
|||||||
// the loading bar will not be completely filled, nor will it be hidden.
|
// the loading bar will not be completely filled, nor will it be hidden.
|
||||||
// To prevent displaying a partially filled loading bar permanently, we
|
// To prevent displaying a partially filled loading bar permanently, we
|
||||||
// hide it when no data has been loaded during a certain amount of time.
|
// hide it when no data has been loaded during a certain amount of time.
|
||||||
if (PDFJS.disableAutoFetch && percent) {
|
const disableAutoFetch = this.pdfDocument ?
|
||||||
|
this.pdfDocument.loadingParams['disableAutoFetch'] :
|
||||||
|
AppOptions.get('disableAutoFetch');
|
||||||
|
|
||||||
|
if (disableAutoFetch && percent) {
|
||||||
if (this.disableAutoFetchLoadingBarTimeout) {
|
if (this.disableAutoFetchLoadingBarTimeout) {
|
||||||
clearTimeout(this.disableAutoFetchLoadingBarTimeout);
|
clearTimeout(this.disableAutoFetchLoadingBarTimeout);
|
||||||
this.disableAutoFetchLoadingBarTimeout = null;
|
this.disableAutoFetchLoadingBarTimeout = null;
|
||||||
|
@ -139,6 +139,11 @@ const defaultOptions = {
|
|||||||
'../external/bcmaps/' : '../web/cmaps/'),
|
'../external/bcmaps/' : '../web/cmaps/'),
|
||||||
kind: OptionKind.API,
|
kind: OptionKind.API,
|
||||||
},
|
},
|
||||||
|
disableAutoFetch: {
|
||||||
|
/** @type {boolean} */
|
||||||
|
value: false,
|
||||||
|
kind: OptionKind.API,
|
||||||
|
},
|
||||||
disableFontFace: {
|
disableFontFace: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: false,
|
value: false,
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { createPromiseCapability, PDFJS } from 'pdfjs-lib';
|
|
||||||
import {
|
import {
|
||||||
CSS_UNITS, DEFAULT_SCALE, DEFAULT_SCALE_VALUE, isValidRotation,
|
CSS_UNITS, DEFAULT_SCALE, DEFAULT_SCALE_VALUE, isValidRotation,
|
||||||
MAX_AUTO_SCALE, NullL10n, PresentationModeState, RendererType,
|
MAX_AUTO_SCALE, NullL10n, PresentationModeState, RendererType,
|
||||||
@ -21,6 +20,7 @@ import {
|
|||||||
} from './ui_utils';
|
} from './ui_utils';
|
||||||
import { PDFRenderingQueue, RenderingStates } from './pdf_rendering_queue';
|
import { PDFRenderingQueue, RenderingStates } from './pdf_rendering_queue';
|
||||||
import { AnnotationLayerBuilder } from './annotation_layer_builder';
|
import { AnnotationLayerBuilder } from './annotation_layer_builder';
|
||||||
|
import { createPromiseCapability } from 'pdfjs-lib';
|
||||||
import { getGlobalEventBus } from './dom_events';
|
import { getGlobalEventBus } from './dom_events';
|
||||||
import { PDFPageView } from './pdf_page_view';
|
import { PDFPageView } from './pdf_page_view';
|
||||||
import { SimpleLinkService } from './pdf_link_service';
|
import { SimpleLinkService } from './pdf_link_service';
|
||||||
@ -408,7 +408,7 @@ class BaseViewer {
|
|||||||
// starts to create the correct size canvas. Wait until one page is
|
// starts to create the correct size canvas. Wait until one page is
|
||||||
// rendered so we don't tie up too many resources early on.
|
// rendered so we don't tie up too many resources early on.
|
||||||
onePageRenderedCapability.promise.then(() => {
|
onePageRenderedCapability.promise.then(() => {
|
||||||
if (PDFJS.disableAutoFetch) {
|
if (pdfDocument.loadingParams['disableAutoFetch']) {
|
||||||
// XXX: Printing is semi-broken with auto fetch disabled.
|
// XXX: Printing is semi-broken with auto fetch disabled.
|
||||||
pagesCapability.resolve();
|
pagesCapability.resolve();
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user