diff --git a/src/core/worker.js b/src/core/worker.js index 4245710e599881..78632f7c2c1883 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -648,7 +648,7 @@ var workerConsole = { // Worker thread? -if (typeof window === 'undefined') { +if (typeof window === 'undefined' && typeof require === 'undefined') { if (!('console' in globalScope)) { globalScope.console = workerConsole; } diff --git a/src/display/api.js b/src/display/api.js index e95409fe714133..1cf5c513e0c8ac 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -19,7 +19,7 @@ if (typeof define === 'function' && define.amd) { define('pdfjs/display/api', ['exports', 'pdfjs/shared/util', 'pdfjs/display/font_loader', 'pdfjs/display/canvas', - 'pdfjs/shared/global'], factory); + 'pdfjs/shared/global', 'require'], factory); } else if (typeof exports !== 'undefined') { factory(exports, require('../shared/util.js'), require('./font_loader.js'), require('./canvas.js'), require('../shared/global.js')); @@ -29,7 +29,7 @@ root.pdfjsSharedGlobal); } }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas, - sharedGlobal) { + sharedGlobal, amdRequire) { var InvalidPDFException = sharedUtil.InvalidPDFException; var MessageHandler = sharedUtil.MessageHandler; @@ -1169,7 +1169,16 @@ var PDFWorker = (function PDFWorkerClosure() { // other files and resolves the promise. In production only the // pdf.worker.js file is needed. //#if !PRODUCTION - Util.loadScript(PDFJS.workerSrc); + if (typeof amdRequire === 'function') { + amdRequire(['pdfjs/core/worker'], function () { + PDFJS.fakeWorkerFilesLoadedCapability.resolve(); + }); + } else if (typeof require === 'function') { + require('../core/worker.js'); + PDFJS.fakeWorkerFilesLoadedCapability.resolve(); + } else { + Util.loadScript(PDFJS.workerSrc); + } //#endif //#if PRODUCTION && SINGLE_FILE // PDFJS.fakeWorkerFilesLoadedCapability.resolve();