pdfjs/web/viewer.js
function pdfViewOpen(file, args) {
          if (arguments.length > 2 || typeof args === 'number') {
            return Promise.reject(new Error('Call of open() with obsolete signature.'));
          }
          if (this.pdfLoadingTask) {
            // We need to destroy already opened document.
            return this.close().then(function () {
              // Reload the preferences if a document was previously opened.
              Preferences.reload();
              // ... and repeat the open() call.
              return this.open(file, args);
            }.bind(this));
          }
          var parameters = Object.create(null), scale;
          if (typeof file === 'string') {
            // URL
            this.setTitleUsingUrl(file);
            parameters.url = file;
          } else if (file && 'byteLength' in file) {
            // ArrayBuffer
            parameters.data = file;
          } else if (file.url && file.originalUrl) {
            this.setTitleUsingUrl(file.originalUrl);
            parameters.url = file.url;
          }
          if (args) {
            for (var prop in args) {
              parameters[prop] = args[prop];
            }
            if (args.scale) {
              scale = args.scale;
            }
            if (args.length) {
              this.pdfDocumentProperties.setFileSize(args.length);
            }
          }
          var self = this;
          self.downloadComplete = false;
          var loadingTask = pdfjsLib.getDocument(parameters);
          this.pdfLoadingTask = loadingTask;
          loadingTask.onPassword = function passwordNeeded(updateCallback, reason) {
            self.passwordPrompt.setUpdateCallback(updateCallback, reason);
            self.passwordPrompt.open();
          };
          loadingTask.onProgress = function getDocumentProgress(progressData) {
            self.progress(progressData.loaded / progressData.total);
          };
          // Listen for unsupported features to trigger the fallback UI.
          loadingTask.onUnsupportedFeature = this.fallback.bind(this);
          return loadingTask.promise.then(function getDocumentCallback(pdfDocument) {
            self.load(pdfDocument, scale);
          }, function getDocumentError(exception) {
            var message = exception && exception.message;
            var loadingErrorMessage = mozL10n.get('loading_error', null, 'An error occurred while loading the PDF.');
            if (exception instanceof pdfjsLib.InvalidPDFException) {
              // change error message also for other builds
              loadingErrorMessage = mozL10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.');
            } else if (exception instanceof pdfjsLib.MissingPDFException) {
              // special message for missing PDF's
              loadingErrorMessage = mozL10n.get('missing_file_error', null, 'Missing PDF file.');
            } else if (exception instanceof pdfjsLib.UnexpectedResponseException) {
              loadingErrorMessage = mozL10n.get('unexpected_response_error', null, 'Unexpected server response.');
            }
            var moreInfo = { message: message };
            self.error(loadingErrorMessage, moreInfo);
            throw new Error(loadingErrorMessage);
          });
        }
function pdfViewOpen(file, args) {
          if (arguments.length > 2 || typeof args === 'number') {
            return Promise.reject(new Error('Call of open() with obsolete signature.'));
          }
          if (this.pdfLoadingTask) {
            // We need to destroy already opened document.
            return this.close().then(function () {
              // Reload the preferences if a document was previously opened.
              Preferences.reload();
              // ... and repeat the open() call.
              return this.open(file, args);
            }.bind(this));
          }
          var parameters = Object.create(null), scale;
          if (typeof file === 'string') {
            // URL
            this.setTitleUsingUrl(file);
            parameters.url = file;
          } else if (file && 'byteLength' in file) {
            // ArrayBuffer
            parameters.data = file;
          } else if (file.url && file.originalUrl) {
            this.setTitleUsingUrl(file.originalUrl);
            parameters.url = file.url;
          }
          if (args) {
            for (var prop in args) {
              parameters[prop] = args[prop];
            }
            if (args.scale) {
              scale = args.scale;
            }
            if (args.length) {
              this.pdfDocumentProperties.setFileSize(args.length);
            }
          }
          var self = this;
          self.downloadComplete = false;
          var loadingTask = pdfjsLib.getDocument(parameters);
          this.pdfLoadingTask = loadingTask;
          loadingTask.onPassword = function passwordNeeded(updateCallback, reason) {
            self.passwordPrompt.setUpdateCallback(updateCallback, reason);
            self.passwordPrompt.open();
          };
          loadingTask.onProgress = function getDocumentProgress(progressData) {
            self.progress(progressData.loaded / progressData.total);
          };
          // Listen for unsupported features to trigger the fallback UI.
          loadingTask.onUnsupportedFeature = this.fallback.bind(this);
          return loadingTask.promise.then(function getDocumentCallback(pdfDocument) {
            self.load(pdfDocument, scale);
          }, function getDocumentError(exception) {
            var message = exception && exception.message;
            var loadingErrorMessage = mozL10n.get('loading_error', null, 'An error occurred while loading the PDF.');
            if (exception instanceof pdfjsLib.InvalidPDFException) {
              // change error message also for other builds
              loadingErrorMessage = mozL10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.');
            } else if (exception instanceof pdfjsLib.MissingPDFException) {
              // special message for missing PDF's
              loadingErrorMessage = mozL10n.get('missing_file_error', null, 'Missing PDF file.');
            } else if (exception instanceof pdfjsLib.UnexpectedResponseException) {
              loadingErrorMessage = mozL10n.get('unexpected_response_error', null, 'Unexpected server response.');
            }
            var moreInfo = { message: message };
            self.error(loadingErrorMessage, moreInfo);
            throw new Error(loadingErrorMessage);
          });
        }
function pdfViewOpen ( file , args ) { if ( arguments . length > 2 || typeof args === 'number' ) { return Promise . reject ( new Error ( 'Call of open() with obsolete signature.' ) ) ; } if ( this . pdfLoadingTask ) { // We need to destroy already opened document. return this . close ( ) . then ( function ( ) { // Reload the preferences if a document was previously opened. Preferences . reload ( ) ; // ... and repeat the open() call. return this . open ( file , args ) ; } . bind ( this ) ) ; } var parameters = Object . create ( null ) , scale ; if ( typeof file === 'string' ) { // URL this . setTitleUsingUrl ( file ) ; parameters . url = file ; } else if ( file && 'byteLength' in file ) { // ArrayBuffer parameters . data = file ; } else if ( file . url && file . originalUrl ) { this . setTitleUsingUrl ( file . originalUrl ) ; parameters . url = file . url ; } if ( args ) { for ( var prop in args ) { parameters [ prop ] = args [ prop ] ; } if ( args . scale ) { scale = args . scale ; } if ( args . length ) { this . pdfDocumentProperties . setFileSize ( args . length ) ; } } var self = this ; self . downloadComplete = false ; var loadingTask = pdfjsLib . getDocument ( parameters ) ; this . pdfLoadingTask = loadingTask ; loadingTask . onPassword = function passwordNeeded ( updateCallback , reason ) { self . passwordPrompt . setUpdateCallback ( updateCallback , reason ) ; self . passwordPrompt . open ( ) ; } ; loadingTask . onProgress = function getDocumentProgress ( progressData ) { self . progress ( progressData . loaded / progressData . total ) ; } ; // Listen for unsupported features to trigger the fallback UI. loadingTask . onUnsupportedFeature = this . fallback . bind ( this ) ; return loadingTask . promise . then ( function getDocumentCallback ( pdfDocument ) { self . load ( pdfDocument , scale ) ; } , function getDocumentError ( exception ) { var message = exception && exception . message ; var loadingErrorMessage = mozL10n . get ( 'loading_error' , null , 'An error occurred while loading the PDF.' ) ; if ( exception instanceof pdfjsLib . InvalidPDFException ) { // change error message also for other builds loadingErrorMessage = mozL10n . get ( 'invalid_file_error' , null , 'Invalid or corrupted PDF file.' ) ; } else if ( exception instanceof pdfjsLib . MissingPDFException ) { // special message for missing PDF's loadingErrorMessage = mozL10n . get ( 'missing_file_error' , null , 'Missing PDF file.' ) ; } else if ( exception instanceof pdfjsLib . UnexpectedResponseException ) { loadingErrorMessage = mozL10n . get ( 'unexpected_response_error' , null , 'Unexpected server response.' ) ; } var moreInfo = { message : message } ; self . error ( loadingErrorMessage , moreInfo ) ; throw new Error ( loadingErrorMessage ) ; } ) ; }
Opens PDF document specified by URL or array with additional arguments.
@param {string|TypedArray|ArrayBuffer} file - PDF location or binary data.
@param {Object} args - (optional) Additional arguments for the getDocument
call, e.g. HTTP headers ('httpHeaders') or
alternative data transport ('range').
@returns {Promise} - Returns the promise, which is resolved when document
is opened.
Opens PDF document specified by URL or array with additional arguments .