Bug 1249508 - Update pdf.js to version 1.4.83. r=bdahl, r=Mossop
authorRyan VanderMeulen <ryanvm@gmail.com>
Thu, 18 Feb 2016 22:01:35 -0500
changeset 321293 7e5ceea9eb9e152860cc2fe2c612ed4c5dc610d9
parent 321292 15d6b3343104ce28acbd85ed0aa5db3ebab38b3b
child 321294 8b65dd9aa149cd88bb39e6eddfa47a5ed8705055
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbdahl, Mossop
bugs1249508
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1249508 - Update pdf.js to version 1.4.83. r=bdahl, r=Mossop
browser/extensions/pdfjs/README.mozilla
browser/extensions/pdfjs/content/PdfStreamConverter.jsm
browser/extensions/pdfjs/content/build/pdf.js
browser/extensions/pdfjs/content/build/pdf.worker.js
browser/extensions/pdfjs/content/web/viewer.html
--- a/browser/extensions/pdfjs/README.mozilla
+++ b/browser/extensions/pdfjs/README.mozilla
@@ -1,3 +1,3 @@
 This is the pdf.js project output, https://github.com/mozilla/pdf.js
 
-Current extension version is: 1.4.64
+Current extension version is: 1.4.83
--- a/browser/extensions/pdfjs/content/PdfStreamConverter.jsm
+++ b/browser/extensions/pdfjs/content/PdfStreamConverter.jsm
@@ -67,19 +67,25 @@ function getFindBar(domWindow) {
   }
   var browser = getContainingBrowser(domWindow);
   try {
     var tabbrowser = browser.getTabBrowser();
     var tab;
     tab = tabbrowser.getTabForBrowser(browser);
     return tabbrowser.getFindBar(tab);
   } catch (e) {
-    // FF22 has no _getTabForBrowser, and FF24 has no getFindBar
-    var chromeWindow = browser.ownerDocument.defaultView;
-    return chromeWindow.gFindBar;
+    try {
+      // FF22 has no _getTabForBrowser, and FF24 has no getFindBar
+      var chromeWindow = browser.ownerDocument.defaultView;
+      return chromeWindow.gFindBar;
+    } catch (ex) {
+      // Suppress errors for PDF files opened in the bookmark sidebar, see
+      // https://bugzilla.mozilla.org/show_bug.cgi?id=1248959.
+      return null;
+    }
   }
 }
 
 function getBoolPref(pref, def) {
   try {
     return Services.prefs.getBoolPref(pref);
   } catch (ex) {
     return def;
@@ -347,17 +353,17 @@ ChromeActions.prototype = {
 
     // ... and we are in a child process
     if (PdfjsContentUtils.isRemote) {
       return true;
     }
 
     // ... or when the new find events code exists.
     var findBar = getFindBar(this.domWindow);
-    return findBar && ('updateControlState' in findBar);
+    return !!findBar && ('updateControlState' in findBar);
   },
   supportsDocumentFonts: function() {
     var prefBrowser = getIntPref('browser.display.use_document_fonts', 1);
     var prefGfx = getBoolPref('gfx.downloadable_fonts.enabled', true);
     return (!!prefBrowser && prefGfx);
   },
   supportsDocumentColors: function() {
     if (getIntPref('browser.display.document_color_use', 0) === 2 ||
--- a/browser/extensions/pdfjs/content/build/pdf.js
+++ b/browser/extensions/pdfjs/content/build/pdf.js
@@ -23,18 +23,18 @@ define('pdfjs-dist/build/pdf', ['exports
     factory(exports);
   } else {
 factory((root.pdfjsDistBuildPdf = {}));
   }
 }(this, function (exports) {
   // Use strict in our context only - users might not want it
   'use strict';
 
-var pdfjsVersion = '1.4.64';
-var pdfjsBuild = '2f145d8';
+var pdfjsVersion = '1.4.83';
+var pdfjsBuild = '0629fd0';
 
   var pdfjsFilePath =
     typeof document !== 'undefined' && document.currentScript ?
       document.currentScript.src : null;
 
   var pdfjsLibs = {};
 
   (function pdfjsWrapper() {
@@ -1624,34 +1624,37 @@ AnnotationElementFactory.prototype =
 
       case AnnotationType.SQUIGGLY:
         return new SquigglyAnnotationElement(parameters);
 
       case AnnotationType.STRIKEOUT:
         return new StrikeOutAnnotationElement(parameters);
 
       default:
-        throw new Error('Unimplemented annotation type "' + subtype + '"');
+        return new AnnotationElement(parameters);
     }
   }
 };
 
 /**
  * @class
  * @alias AnnotationElement
  */
 var AnnotationElement = (function AnnotationElementClosure() {
-  function AnnotationElement(parameters) {
+  function AnnotationElement(parameters, isRenderable) {
+    this.isRenderable = isRenderable || false;
     this.data = parameters.data;
     this.layer = parameters.layer;
     this.page = parameters.page;
     this.viewport = parameters.viewport;
     this.linkService = parameters.linkService;
 
-    this.container = this._createContainer();
+    if (isRenderable) {
+      this.container = this._createContainer();
+    }
   }
 
   AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {
     /**
      * Create an empty container for the annotation's HTML element.
      *
      * @private
      * @memberof AnnotationElement
@@ -1756,17 +1759,17 @@ var AnnotationElement = (function Annota
 })();
 
 /**
  * @class
  * @alias LinkAnnotationElement
  */
 var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
   function LinkAnnotationElement(parameters) {
-    AnnotationElement.call(this, parameters);
+    AnnotationElement.call(this, parameters, true);
   }
 
   Util.inherit(LinkAnnotationElement, AnnotationElement, {
     /**
      * Render the link annotation's HTML element in the empty container.
      *
      * @public
      * @memberof LinkAnnotationElement
@@ -1838,17 +1841,19 @@ var LinkAnnotationElement = (function Li
 })();
 
 /**
  * @class
  * @alias TextAnnotationElement
  */
 var TextAnnotationElement = (function TextAnnotationElementClosure() {
   function TextAnnotationElement(parameters) {
-    AnnotationElement.call(this, parameters);
+    var isRenderable = !!(parameters.data.hasPopup ||
+                          parameters.data.title || parameters.data.contents);
+    AnnotationElement.call(this, parameters, isRenderable);
   }
 
   Util.inherit(TextAnnotationElement, AnnotationElement, {
     /**
      * Render the text annotation's HTML element in the empty container.
      *
      * @public
      * @memberof TextAnnotationElement
@@ -1892,17 +1897,19 @@ var TextAnnotationElement = (function Te
 })();
 
 /**
  * @class
  * @alias WidgetAnnotationElement
  */
 var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
   function WidgetAnnotationElement(parameters) {
-    AnnotationElement.call(this, parameters);
+    var isRenderable = !parameters.data.hasAppearance &&
+                       !!parameters.data.fieldValue;
+    AnnotationElement.call(this, parameters, isRenderable);
   }
 
   Util.inherit(WidgetAnnotationElement, AnnotationElement, {
     /**
      * Render the widget annotation's HTML element in the empty container.
      *
      * @public
      * @memberof WidgetAnnotationElement
@@ -1959,17 +1966,18 @@ var WidgetAnnotationElement = (function 
 })();
 
 /**
  * @class
  * @alias PopupAnnotationElement
  */
 var PopupAnnotationElement = (function PopupAnnotationElementClosure() {
   function PopupAnnotationElement(parameters) {
-    AnnotationElement.call(this, parameters);
+    var isRenderable = !!(parameters.data.title || parameters.data.contents);
+    AnnotationElement.call(this, parameters, isRenderable);
   }
 
   Util.inherit(PopupAnnotationElement, AnnotationElement, {
     /**
      * Render the popup annotation's HTML element in the empty container.
      *
      * @public
      * @memberof PopupAnnotationElement
@@ -2149,17 +2157,17 @@ var PopupElement = (function PopupElemen
 
 /**
  * @class
  * @alias HighlightAnnotationElement
  */
 var HighlightAnnotationElement = (
     function HighlightAnnotationElementClosure() {
   function HighlightAnnotationElement(parameters) {
-    AnnotationElement.call(this, parameters);
+    AnnotationElement.call(this, parameters, true);
   }
 
   Util.inherit(HighlightAnnotationElement, AnnotationElement, {
     /**
      * Render the highlight annotation's HTML element in the empty container.
      *
      * @public
      * @memberof HighlightAnnotationElement
@@ -2176,17 +2184,17 @@ var HighlightAnnotationElement = (
 
 /**
  * @class
  * @alias UnderlineAnnotationElement
  */
 var UnderlineAnnotationElement = (
     function UnderlineAnnotationElementClosure() {
   function UnderlineAnnotationElement(parameters) {
-    AnnotationElement.call(this, parameters);
+    AnnotationElement.call(this, parameters, true);
   }
 
   Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
     /**
      * Render the underline annotation's HTML element in the empty container.
      *
      * @public
      * @memberof UnderlineAnnotationElement
@@ -2202,17 +2210,17 @@ var UnderlineAnnotationElement = (
 })();
 
 /**
  * @class
  * @alias SquigglyAnnotationElement
  */
 var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() {
   function SquigglyAnnotationElement(parameters) {
-    AnnotationElement.call(this, parameters);
+    AnnotationElement.call(this, parameters, true);
   }
 
   Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
     /**
      * Render the squiggly annotation's HTML element in the empty container.
      *
      * @public
      * @memberof SquigglyAnnotationElement
@@ -2229,17 +2237,17 @@ var SquigglyAnnotationElement = (functio
 
 /**
  * @class
  * @alias StrikeOutAnnotationElement
  */
 var StrikeOutAnnotationElement = (
     function StrikeOutAnnotationElementClosure() {
   function StrikeOutAnnotationElement(parameters) {
-    AnnotationElement.call(this, parameters);
+    AnnotationElement.call(this, parameters, true);
   }
 
   Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
     /**
      * Render the strikeout annotation's HTML element in the empty container.
      *
      * @public
      * @memberof StrikeOutAnnotationElement
@@ -2276,29 +2284,31 @@ var AnnotationLayer = (function Annotati
      * @param {AnnotationLayerParameters} parameters
      * @memberof AnnotationLayer
      */
     render: function AnnotationLayer_render(parameters) {
       var annotationElementFactory = new AnnotationElementFactory();
 
       for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
         var data = parameters.annotations[i];
-        if (!data || !data.hasHtml) {
+        if (!data) {
           continue;
         }
 
         var properties = {
           data: data,
           layer: parameters.div,
           page: parameters.page,
           viewport: parameters.viewport,
           linkService: parameters.linkService
         };
         var element = annotationElementFactory.create(properties);
-        parameters.div.appendChild(element.render());
+        if (element.isRenderable) {
+          parameters.div.appendChild(element.render());
+        }
       }
     },
 
     /**
      * Update the annotation elements on existing annotation layer.
      *
      * @public
      * @param {AnnotationLayerParameters} parameters
@@ -6560,17 +6570,17 @@ var PDFDocumentProxy = (function PDFDocu
     /**
      * @return {Promise} A promise that is resolved with an {Array} that is a
      * tree outline (if it has one) of the PDF. The tree is in the format of:
      * [
      *  {
      *   title: string,
      *   bold: boolean,
      *   italic: boolean,
-     *   color: rgb array,
+     *   color: rgb Uint8Array,
      *   dest: dest obj,
      *   url: string,
      *   items: array of more items like this
      *  },
      *  ...
      * ].
      */
     getOutline: function PDFDocumentProxy_getOutline() {
--- a/browser/extensions/pdfjs/content/build/pdf.worker.js
+++ b/browser/extensions/pdfjs/content/build/pdf.worker.js
@@ -23,18 +23,18 @@ define('pdfjs-dist/build/pdf.worker', ['
     factory(exports);
   } else {
 factory((root.pdfjsDistBuildPdfWorker = {}));
   }
 }(this, function (exports) {
   // Use strict in our context only - users might not want it
   'use strict';
 
-var pdfjsVersion = '1.4.64';
-var pdfjsBuild = '2f145d8';
+var pdfjsVersion = '1.4.83';
+var pdfjsBuild = '0629fd0';
 
   var pdfjsFilePath =
     typeof document !== 'undefined' && document.currentScript ?
       document.currentScript.src : null;
 
   var pdfjsLibs = {};
 
   (function pdfjsWrapper() {
@@ -1610,17 +1610,28 @@ var JpegImage = (function jpegImage() {
 
     getData: function getData(width, height, forceRGBoutput) {
       if (this.numComponents > 4) {
         throw 'Unsupported color mode';
       }
       // type of data: Uint8Array(width * height * numComponents)
       var data = this._getLinearizedBlockData(width, height);
 
-      if (this.numComponents === 3) {
+      if (this.numComponents === 1 && forceRGBoutput) {
+        var dataLength = data.length;
+        var rgbData = new Uint8Array(dataLength * 3);
+        var offset = 0;
+        for (var i = 0; i < dataLength; i++) {
+          var grayColor = data[i];
+          rgbData[offset++] = grayColor;
+          rgbData[offset++] = grayColor;
+          rgbData[offset++] = grayColor;
+        }
+        return rgbData;
+      } else if (this.numComponents === 3) {
         return this._convertYccToRgb(data);
       } else if (this.numComponents === 4) {
         if (this._isColorConversionNeeded()) {
           if (forceRGBoutput) {
             return this._convertYcckToRgb(data);
           } else {
             return this._convertYcckToCmyk(data);
           }
@@ -14925,34 +14936,16 @@ var Cmd = (function CmdClosure() {
   return Cmd;
 })();
 
 var Dict = (function DictClosure() {
   var nonSerializable = function nonSerializableClosure() {
     return nonSerializable; // creating closure on some variable
   };
 
-  var GETALL_DICTIONARY_TYPES_WHITELIST = {
-    'Background': true,
-    'ExtGState': true,
-    'Halftone': true,
-    'Layout': true,
-    'Mask': true,
-    'Pagination': true,
-    'Printing': true
-  };
-
-  function isRecursionAllowedFor(dict) {
-    if (!isName(dict.Type)) {
-      return true;
-    }
-    var dictType = dict.Type.name;
-    return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
-  }
-
   // xref is optional
   function Dict(xref) {
     // Map should only be used internally, use functions below to access.
     this.map = Object.create(null);
     this.xref = xref;
     this.objId = null;
     this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
   }
@@ -15020,68 +15013,16 @@ var Dict = (function DictClosure() {
       return value;
     },
 
     // no dereferencing
     getRaw: function Dict_getRaw(key) {
       return this.map[key];
     },
 
-    // creates new map and dereferences all Refs
-    getAll: function Dict_getAll() {
-      var all = Object.create(null);
-      var queue = null;
-      var key, obj;
-      for (key in this.map) {
-        obj = this.get(key);
-        if (obj instanceof Dict) {
-          if (isRecursionAllowedFor(obj)) {
-            (queue || (queue = [])).push({target: all, key: key, obj: obj});
-          } else {
-            all[key] = this.getRaw(key);
-          }
-        } else {
-          all[key] = obj;
-        }
-      }
-      if (!queue) {
-        return all;
-      }
-
-      // trying to take cyclic references into the account
-      var processed = Object.create(null);
-      while (queue.length > 0) {
-        var item = queue.shift();
-        var itemObj = item.obj;
-        var objId = itemObj.objId;
-        if (objId && objId in processed) {
-          item.target[item.key] = processed[objId];
-          continue;
-        }
-        var dereferenced = Object.create(null);
-        for (key in itemObj.map) {
-          obj = itemObj.get(key);
-          if (obj instanceof Dict) {
-            if (isRecursionAllowedFor(obj)) {
-              queue.push({target: dereferenced, key: key, obj: obj});
-            } else {
-              dereferenced[key] = itemObj.getRaw(key);
-            }
-          } else {
-            dereferenced[key] = obj;
-          }
-        }
-        if (objId) {
-          processed[objId] = dereferenced;
-        }
-        item.target[item.key] = dereferenced;
-      }
-      return all;
-    },
-
     getKeys: function Dict_getKeys() {
       return Object.keys(this.map);
     },
 
     set: function Dict_set(key, value) {
       this.map[key] = value;
     },
 
@@ -24600,1587 +24541,16 @@ var CMapFactory = (function CMapFactoryC
 exports.CMap = CMap;
 exports.CMapFactory = CMapFactory;
 exports.IdentityCMap = IdentityCMap;
 }));
 
 
 (function (root, factory) {
   {
-    factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
-      root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
-      root.pdfjsCoreChunkedStream);
-  }
-}(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
-                  coreChunkedStream) {
-
-var InvalidPDFException = sharedUtil.InvalidPDFException;
-var MissingDataException = sharedUtil.MissingDataException;
-var XRefParseException = sharedUtil.XRefParseException;
-var assert = sharedUtil.assert;
-var bytesToString = sharedUtil.bytesToString;
-var createPromiseCapability = sharedUtil.createPromiseCapability;
-var error = sharedUtil.error;
-var info = sharedUtil.info;
-var isArray = sharedUtil.isArray;
-var isInt = sharedUtil.isInt;
-var isString = sharedUtil.isString;
-var shadow = sharedUtil.shadow;
-var stringToPDFString = sharedUtil.stringToPDFString;
-var stringToUTF8String = sharedUtil.stringToUTF8String;
-var warn = sharedUtil.warn;
-var isValidUrl = sharedUtil.isValidUrl;
-var Util = sharedUtil.Util;
-var Ref = corePrimitives.Ref;
-var RefSet = corePrimitives.RefSet;
-var RefSetCache = corePrimitives.RefSetCache;
-var isName = corePrimitives.isName;
-var isCmd = corePrimitives.isCmd;
-var isDict = corePrimitives.isDict;
-var isRef = corePrimitives.isRef;
-var isStream = corePrimitives.isStream;
-var CipherTransformFactory = coreCrypto.CipherTransformFactory;
-var Lexer = coreParser.Lexer;
-var Parser = coreParser.Parser;
-var ChunkedStream = coreChunkedStream.ChunkedStream;
-
-var Catalog = (function CatalogClosure() {
-  function Catalog(pdfManager, xref, pageFactory) {
-    this.pdfManager = pdfManager;
-    this.xref = xref;
-    this.catDict = xref.getCatalogObj();
-    this.fontCache = new RefSetCache();
-    assert(isDict(this.catDict),
-      'catalog object is not a dictionary');
-
-    // TODO refactor to move getPage() to the PDFDocument.
-    this.pageFactory = pageFactory;
-    this.pagePromises = [];
-  }
-
-  Catalog.prototype = {
-    get metadata() {
-      var streamRef = this.catDict.getRaw('Metadata');
-      if (!isRef(streamRef)) {
-        return shadow(this, 'metadata', null);
-      }
-
-      var encryptMetadata = (!this.xref.encrypt ? false :
-                             this.xref.encrypt.encryptMetadata);
-
-      var stream = this.xref.fetch(streamRef, !encryptMetadata);
-      var metadata;
-      if (stream && isDict(stream.dict)) {
-        var type = stream.dict.get('Type');
-        var subtype = stream.dict.get('Subtype');
-
-        if (isName(type) && isName(subtype) &&
-            type.name === 'Metadata' && subtype.name === 'XML') {
-          // XXX: This should examine the charset the XML document defines,
-          // however since there are currently no real means to decode
-          // arbitrary charsets, let's just hope that the author of the PDF
-          // was reasonable enough to stick with the XML default charset,
-          // which is UTF-8.
-          try {
-            metadata = stringToUTF8String(bytesToString(stream.getBytes()));
-          } catch (e) {
-            info('Skipping invalid metadata.');
-          }
-        }
-      }
-
-      return shadow(this, 'metadata', metadata);
-    },
-    get toplevelPagesDict() {
-      var pagesObj = this.catDict.get('Pages');
-      assert(isDict(pagesObj), 'invalid top-level pages dictionary');
-      // shadow the prototype getter
-      return shadow(this, 'toplevelPagesDict', pagesObj);
-    },
-    get documentOutline() {
-      var obj = null;
-      try {
-        obj = this.readDocumentOutline();
-      } catch (ex) {
-        if (ex instanceof MissingDataException) {
-          throw ex;
-        }
-        warn('Unable to read document outline');
-      }
-      return shadow(this, 'documentOutline', obj);
-    },
-    readDocumentOutline: function Catalog_readDocumentOutline() {
-      var xref = this.xref;
-      var obj = this.catDict.get('Outlines');
-      var root = { items: [] };
-      if (isDict(obj)) {
-        obj = obj.getRaw('First');
-        var processed = new RefSet();
-        if (isRef(obj)) {
-          var queue = [{obj: obj, parent: root}];
-          // to avoid recursion keeping track of the items
-          // in the processed dictionary
-          processed.put(obj);
-          while (queue.length > 0) {
-            var i = queue.shift();
-            var outlineDict = xref.fetchIfRef(i.obj);
-            if (outlineDict === null) {
-              continue;
-            }
-            if (!outlineDict.has('Title')) {
-              error('Invalid outline item');
-            }
-            var actionDict = outlineDict.get('A'), dest = null, url = null;
-            if (actionDict) {
-              var destEntry = actionDict.get('D');
-              if (destEntry) {
-                dest = destEntry;
-              } else {
-                var uriEntry = actionDict.get('URI');
-                if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
-                  url = uriEntry;
-                }
-              }
-            } else if (outlineDict.has('Dest')) {
-              dest = outlineDict.getRaw('Dest');
-              if (isName(dest)) {
-                dest = dest.name;
-              }
-            }
-            var title = outlineDict.get('Title');
-            var outlineItem = {
-              dest: dest,
-              url: url,
-              title: stringToPDFString(title),
-              color: outlineDict.get('C') || [0, 0, 0],
-              count: outlineDict.get('Count'),
-              bold: !!(outlineDict.get('F') & 2),
-              italic: !!(outlineDict.get('F') & 1),
-              items: []
-            };
-            i.parent.items.push(outlineItem);
-            obj = outlineDict.getRaw('First');
-            if (isRef(obj) && !processed.has(obj)) {
-              queue.push({obj: obj, parent: outlineItem});
-              processed.put(obj);
-            }
-            obj = outlineDict.getRaw('Next');
-            if (isRef(obj) && !processed.has(obj)) {
-              queue.push({obj: obj, parent: i.parent});
-              processed.put(obj);
-            }
-          }
-        }
-      }
-      return (root.items.length > 0 ? root.items : null);
-    },
-    get numPages() {
-      var obj = this.toplevelPagesDict.get('Count');
-      assert(
-        isInt(obj),
-        'page count in top level pages object is not an integer'
-      );
-      // shadow the prototype getter
-      return shadow(this, 'num', obj);
-    },
-    get destinations() {
-      function fetchDestination(dest) {
-        return isDict(dest) ? dest.get('D') : dest;
-      }
-
-      var xref = this.xref;
-      var dests = {}, nameTreeRef, nameDictionaryRef;
-      var obj = this.catDict.get('Names');
-      if (obj && obj.has('Dests')) {
-        nameTreeRef = obj.getRaw('Dests');
-      } else if (this.catDict.has('Dests')) {
-        nameDictionaryRef = this.catDict.get('Dests');
-      }
-
-      if (nameDictionaryRef) {
-        // reading simple destination dictionary
-        obj = nameDictionaryRef;
-        obj.forEach(function catalogForEach(key, value) {
-          if (!value) {
-            return;
-          }
-          dests[key] = fetchDestination(value);
-        });
-      }
-      if (nameTreeRef) {
-        var nameTree = new NameTree(nameTreeRef, xref);
-        var names = nameTree.getAll();
-        for (var name in names) {
-          dests[name] = fetchDestination(names[name]);
-        }
-      }
-      return shadow(this, 'destinations', dests);
-    },
-    getDestination: function Catalog_getDestination(destinationId) {
-      function fetchDestination(dest) {
-        return isDict(dest) ? dest.get('D') : dest;
-      }
-
-      var xref = this.xref;
-      var dest = null, nameTreeRef, nameDictionaryRef;
-      var obj = this.catDict.get('Names');
-      if (obj && obj.has('Dests')) {
-        nameTreeRef = obj.getRaw('Dests');
-      } else if (this.catDict.has('Dests')) {
-        nameDictionaryRef = this.catDict.get('Dests');
-      }
-
-      if (nameDictionaryRef) { // Simple destination dictionary.
-        var value = nameDictionaryRef.get(destinationId);
-        if (value) {
-          dest = fetchDestination(value);
-        }
-      }
-      if (nameTreeRef) {
-        var nameTree = new NameTree(nameTreeRef, xref);
-        dest = fetchDestination(nameTree.get(destinationId));
-      }
-      return dest;
-    },
-
-    get pageLabels() {
-      var obj = null;
-      try {
-        obj = this.readPageLabels();
-      } catch (ex) {
-        if (ex instanceof MissingDataException) {
-          throw ex;
-        }
-        warn('Unable to read page labels.');
-      }
-      return shadow(this, 'pageLabels', obj);
-    },
-    readPageLabels: function Catalog_readPageLabels() {
-      var obj = this.catDict.getRaw('PageLabels');
-      if (!obj) {
-        return null;
-      }
-      var pageLabels = new Array(this.numPages);
-      var style = null;
-      var prefix = '';
-      var start = 1;
-
-      var numberTree = new NumberTree(obj, this.xref);
-      var nums = numberTree.getAll();
-      var currentLabel = '', currentIndex = 1;
-
-      for (var i = 0, ii = this.numPages; i < ii; i++) {
-        if (i in nums) {
-          var labelDict = nums[i];
-          assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
-
-          var type = labelDict.get('Type');
-          assert(!type || (isName(type) && type.name === 'PageLabel'),
-                 'Invalid type in PageLabel dictionary.');
-
-          var s = labelDict.get('S');
-          assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
-          style = (s ? s.name : null);
-
-          prefix = labelDict.get('P') || '';
-          assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
-
-          start = labelDict.get('St') || 1;
-          assert(isInt(start), 'Invalid start in PageLabel dictionary.');
-          currentIndex = start;
-        }
-
-        switch (style) {
-          case 'D':
-            currentLabel = currentIndex;
-            break;
-          case 'R':
-          case 'r':
-            currentLabel = Util.toRoman(currentIndex, style === 'r');
-            break;
-          case 'A':
-          case 'a':
-            var LIMIT = 26; // Use only the characters A--Z, or a--z.
-            var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
-
-            var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
-            var letterIndex = currentIndex - 1;
-            var character = String.fromCharCode(baseCharCode +
-                                                (letterIndex % LIMIT));
-            var charBuf = [];
-            for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
-              charBuf.push(character);
-            }
-            currentLabel = charBuf.join('');
-            break;
-          default:
-            assert(!style,
-                   'Invalid style "' + style + '" in PageLabel dictionary.');
-        }
-        pageLabels[i] = prefix + currentLabel;
-
-        currentLabel = '';
-        currentIndex++;
-      }
-      return pageLabels;
-    },
-
-    get attachments() {
-      var xref = this.xref;
-      var attachments = null, nameTreeRef;
-      var obj = this.catDict.get('Names');
-      if (obj) {
-        nameTreeRef = obj.getRaw('EmbeddedFiles');
-      }
-
-      if (nameTreeRef) {
-        var nameTree = new NameTree(nameTreeRef, xref);
-        var names = nameTree.getAll();
-        for (var name in names) {
-          var fs = new FileSpec(names[name], xref);
-          if (!attachments) {
-            attachments = Object.create(null);
-          }
-          attachments[stringToPDFString(name)] = fs.serializable;
-        }
-      }
-      return shadow(this, 'attachments', attachments);
-    },
-    get javaScript() {
-      var xref = this.xref;
-      var obj = this.catDict.get('Names');
-
-      var javaScript = [];
-      function appendIfJavaScriptDict(jsDict) {
-        var type = jsDict.get('S');
-        if (!isName(type) || type.name !== 'JavaScript') {
-          return;
-        }
-        var js = jsDict.get('JS');
-        if (isStream(js)) {
-          js = bytesToString(js.getBytes());
-        } else if (!isString(js)) {
-          return;
-        }
-        javaScript.push(stringToPDFString(js));
-      }
-      if (obj && obj.has('JavaScript')) {
-        var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
-        var names = nameTree.getAll();
-        for (var name in names) {
-          // We don't really use the JavaScript right now. This code is
-          // defensive so we don't cause errors on document load.
-          var jsDict = names[name];
-          if (isDict(jsDict)) {
-            appendIfJavaScriptDict(jsDict);
-          }
-        }
-      }
-
-      // Append OpenAction actions to javaScript array
-      var openactionDict = this.catDict.get('OpenAction');
-      if (isDict(openactionDict, 'Action')) {
-        var actionType = openactionDict.get('S');
-        if (isName(actionType) && actionType.name === 'Named') {
-          // The named Print action is not a part of the PDF 1.7 specification,
-          // but is supported by many PDF readers/writers (including Adobe's).
-          var action = openactionDict.get('N');
-          if (isName(action) && action.name === 'Print') {
-            javaScript.push('print({});');
-          }
-        } else {
-          appendIfJavaScriptDict(openactionDict);
-        }
-      }
-
-      return shadow(this, 'javaScript', javaScript);
-    },
-
-    cleanup: function Catalog_cleanup() {
-      var promises = [];
-      this.fontCache.forEach(function (promise) {
-        promises.push(promise);
-      });
-      return Promise.all(promises).then(function (translatedFonts) {
-        for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
-          var font = translatedFonts[i].dict;
-          delete font.translated;
-        }
-        this.fontCache.clear();
-      }.bind(this));
-    },
-
-    getPage: function Catalog_getPage(pageIndex) {
-      if (!(pageIndex in this.pagePromises)) {
-        this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
-          function (a) {
-            var dict = a[0];
-            var ref = a[1];
-            return this.pageFactory.createPage(pageIndex, dict, ref,
-                                               this.fontCache);
-          }.bind(this)
-        );
-      }
-      return this.pagePromises[pageIndex];
-    },
-
-    getPageDict: function Catalog_getPageDict(pageIndex) {
-      var capability = createPromiseCapability();
-      var nodesToVisit = [this.catDict.getRaw('Pages')];
-      var currentPageIndex = 0;
-      var xref = this.xref;
-      var checkAllKids = false;
-
-      function next() {
-        while (nodesToVisit.length) {
-          var currentNode = nodesToVisit.pop();
-
-          if (isRef(currentNode)) {
-            xref.fetchAsync(currentNode).then(function (obj) {
-              if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
-                if (pageIndex === currentPageIndex) {
-                  capability.resolve([obj, currentNode]);
-                } else {
-                  currentPageIndex++;
-                  next();
-                }
-                return;
-              }
-              nodesToVisit.push(obj);
-              next();
-            }, capability.reject);
-            return;
-          }
-
-          // Must be a child page dictionary.
-          assert(
-            isDict(currentNode),
-            'page dictionary kid reference points to wrong type of object'
-          );
-          var count = currentNode.get('Count');
-          // If the current node doesn't have any children, avoid getting stuck
-          // in an empty node further down in the tree (see issue5644.pdf).
-          if (count === 0) {
-            checkAllKids = true;
-          }
-          // Skip nodes where the page can't be.
-          if (currentPageIndex + count <= pageIndex) {
-            currentPageIndex += count;
-            continue;
-          }
-
-          var kids = currentNode.get('Kids');
-          assert(isArray(kids), 'page dictionary kids object is not an array');
-          if (!checkAllKids && count === kids.length) {
-            // Nodes that don't have the page have been skipped and this is the
-            // bottom of the tree which means the page requested must be a
-            // descendant of this pages node. Ideally we would just resolve the
-            // promise with the page ref here, but there is the case where more
-            // pages nodes could link to single a page (see issue 3666 pdf). To
-            // handle this push it back on the queue so if it is a pages node it
-            // will be descended into.
-            nodesToVisit = [kids[pageIndex - currentPageIndex]];
-            currentPageIndex = pageIndex;
-            continue;
-          } else {
-            for (var last = kids.length - 1; last >= 0; last--) {
-              nodesToVisit.push(kids[last]);
-            }
-          }
-        }
-        capability.reject('Page index ' + pageIndex + ' not found.');
-      }
-      next();
-      return capability.promise;
-    },
-
-    getPageIndex: function Catalog_getPageIndex(ref) {
-      // The page tree nodes have the count of all the leaves below them. To get
-      // how many pages are before we just have to walk up the tree and keep
-      // adding the count of siblings to the left of the node.
-      var xref = this.xref;
-      function pagesBeforeRef(kidRef) {
-        var total = 0;
-        var parentRef;
-        return xref.fetchAsync(kidRef).then(function (node) {
-          if (!node) {
-            return null;
-          }
-          parentRef = node.getRaw('Parent');
-          return node.getAsync('Parent');
-        }).then(function (parent) {
-          if (!parent) {
-            return null;
-          }
-          return parent.getAsync('Kids');
-        }).then(function (kids) {
-          if (!kids) {
-            return null;
-          }
-          var kidPromises = [];
-          var found = false;
-          for (var i = 0; i < kids.length; i++) {
-            var kid = kids[i];
-            assert(isRef(kid), 'kids must be a ref');
-            if (kid.num === kidRef.num) {
-              found = true;
-              break;
-            }
-            kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
-              if (kid.has('Count')) {
-                var count = kid.get('Count');
-                total += count;
-              } else { // page leaf node
-                total++;
-              }
-            }));
-          }
-          if (!found) {
-            error('kid ref not found in parents kids');
-          }
-          return Promise.all(kidPromises).then(function () {
-            return [total, parentRef];
-          });
-        });
-      }
-
-      var total = 0;
-      function next(ref) {
-        return pagesBeforeRef(ref).then(function (args) {
-          if (!args) {
-            return total;
-          }
-          var count = args[0];
-          var parentRef = args[1];
-          total += count;
-          return next(parentRef);
-        });
-      }
-
-      return next(ref);
-    }
-  };
-
-  return Catalog;
-})();
-
-var XRef = (function XRefClosure() {
-  function XRef(stream, password) {
-    this.stream = stream;
-    this.entries = [];
-    this.xrefstms = Object.create(null);
-    // prepare the XRef cache
-    this.cache = [];
-    this.password = password;
-    this.stats = {
-      streamTypes: [],
-      fontTypes: []
-    };
-  }
-
-  XRef.prototype = {
-    setStartXRef: function XRef_setStartXRef(startXRef) {
-      // Store the starting positions of xref tables as we process them
-      // so we can recover from missing data errors
-      this.startXRefQueue = [startXRef];
-    },
-
-    parse: function XRef_parse(recoveryMode) {
-      var trailerDict;
-      if (!recoveryMode) {
-        trailerDict = this.readXRef();
-      } else {
-        warn('Indexing all PDF objects');
-        trailerDict = this.indexObjects();
-      }
-      trailerDict.assignXref(this);
-      this.trailer = trailerDict;
-      var encrypt = trailerDict.get('Encrypt');
-      if (encrypt) {
-        var ids = trailerDict.get('ID');
-        var fileId = (ids && ids.length) ? ids[0] : '';
-        this.encrypt = new CipherTransformFactory(encrypt, fileId,
-                                                  this.password);
-      }
-
-      // get the root dictionary (catalog) object
-      if (!(this.root = trailerDict.get('Root'))) {
-        error('Invalid root reference');
-      }
-    },
-
-    processXRefTable: function XRef_processXRefTable(parser) {
-      if (!('tableState' in this)) {
-        // Stores state of the table as we process it so we can resume
-        // from middle of table in case of missing data error
-        this.tableState = {
-          entryNum: 0,
-          streamPos: parser.lexer.stream.pos,
-          parserBuf1: parser.buf1,
-          parserBuf2: parser.buf2
-        };
-      }
-
-      var obj = this.readXRefTable(parser);
-
-      // Sanity check
-      if (!isCmd(obj, 'trailer')) {
-        error('Invalid XRef table: could not find trailer dictionary');
-      }
-      // Read trailer dictionary, e.g.
-      // trailer
-      //    << /Size 22
-      //      /Root 20R
-      //      /Info 10R
-      //      /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
-      //    >>
-      // The parser goes through the entire stream << ... >> and provides
-      // a getter interface for the key-value table
-      var dict = parser.getObj();
-
-      // The pdflib PDF generator can generate a nested trailer dictionary
-      if (!isDict(dict) && dict.dict) {
-        dict = dict.dict;
-      }
-      if (!isDict(dict)) {
-        error('Invalid XRef table: could not parse trailer dictionary');
-      }
-      delete this.tableState;
-
-      return dict;
-    },
-
-    readXRefTable: function XRef_readXRefTable(parser) {
-      // Example of cross-reference table:
-      // xref
-      // 0 1                    <-- subsection header (first obj #, obj count)
-      // 0000000000 65535 f     <-- actual object (offset, generation #, f/n)
-      // 23 2                   <-- subsection header ... and so on ...
-      // 0000025518 00002 n
-      // 0000025635 00000 n
-      // trailer
-      // ...
-
-      var stream = parser.lexer.stream;
-      var tableState = this.tableState;
-      stream.pos = tableState.streamPos;
-      parser.buf1 = tableState.parserBuf1;
-      parser.buf2 = tableState.parserBuf2;
-
-      // Outer loop is over subsection headers
-      var obj;
-
-      while (true) {
-        if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
-          if (isCmd(obj = parser.getObj(), 'trailer')) {
-            break;
-          }
-          tableState.firstEntryNum = obj;
-          tableState.entryCount = parser.getObj();
-        }
-
-        var first = tableState.firstEntryNum;
-        var count = tableState.entryCount;
-        if (!isInt(first) || !isInt(count)) {
-          error('Invalid XRef table: wrong types in subsection header');
-        }
-        // Inner loop is over objects themselves
-        for (var i = tableState.entryNum; i < count; i++) {
-          tableState.streamPos = stream.pos;
-          tableState.entryNum = i;
-          tableState.parserBuf1 = parser.buf1;
-          tableState.parserBuf2 = parser.buf2;
-
-          var entry = {};
-          entry.offset = parser.getObj();
-          entry.gen = parser.getObj();
-          var type = parser.getObj();
-
-          if (isCmd(type, 'f')) {
-            entry.free = true;
-          } else if (isCmd(type, 'n')) {
-            entry.uncompressed = true;
-          }
-
-          // Validate entry obj
-          if (!isInt(entry.offset) || !isInt(entry.gen) ||
-              !(entry.free || entry.uncompressed)) {
-            error('Invalid entry in XRef subsection: ' + first + ', ' + count);
-          }
-
-          if (!this.entries[i + first]) {
-            this.entries[i + first] = entry;
-          }
-        }
-
-        tableState.entryNum = 0;
-        tableState.streamPos = stream.pos;
-        tableState.parserBuf1 = parser.buf1;
-        tableState.parserBuf2 = parser.buf2;
-        delete tableState.firstEntryNum;
-        delete tableState.entryCount;
-      }
-
-      // Per issue 3248: hp scanners generate bad XRef
-      if (first === 1 && this.entries[1] && this.entries[1].free) {
-        // shifting the entries
-        this.entries.shift();
-      }
-
-      // Sanity check: as per spec, first object must be free
-      if (this.entries[0] && !this.entries[0].free) {
-        error('Invalid XRef table: unexpected first object');
-      }
-      return obj;
-    },
-
-    processXRefStream: function XRef_processXRefStream(stream) {
-      if (!('streamState' in this)) {
-        // Stores state of the stream as we process it so we can resume
-        // from middle of stream in case of missing data error
-        var streamParameters = stream.dict;
-        var byteWidths = streamParameters.get('W');
-        var range = streamParameters.get('Index');
-        if (!range) {
-          range = [0, streamParameters.get('Size')];
-        }
-
-        this.streamState = {
-          entryRanges: range,
-          byteWidths: byteWidths,
-          entryNum: 0,
-          streamPos: stream.pos
-        };
-      }
-      this.readXRefStream(stream);
-      delete this.streamState;
-
-      return stream.dict;
-    },
-
-    readXRefStream: function XRef_readXRefStream(stream) {
-      var i, j;
-      var streamState = this.streamState;
-      stream.pos = streamState.streamPos;
-
-      var byteWidths = streamState.byteWidths;
-      var typeFieldWidth = byteWidths[0];
-      var offsetFieldWidth = byteWidths[1];
-      var generationFieldWidth = byteWidths[2];
-
-      var entryRanges = streamState.entryRanges;
-      while (entryRanges.length > 0) {
-        var first = entryRanges[0];
-        var n = entryRanges[1];
-
-        if (!isInt(first) || !isInt(n)) {
-          error('Invalid XRef range fields: ' + first + ', ' + n);
-        }
-        if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
-            !isInt(generationFieldWidth)) {
-          error('Invalid XRef entry fields length: ' + first + ', ' + n);
-        }
-        for (i = streamState.entryNum; i < n; ++i) {
-          streamState.entryNum = i;
-          streamState.streamPos = stream.pos;
-
-          var type = 0, offset = 0, generation = 0;
-          for (j = 0; j < typeFieldWidth; ++j) {
-            type = (type << 8) | stream.getByte();
-          }
-          // if type field is absent, its default value is 1
-          if (typeFieldWidth === 0) {
-            type = 1;
-          }
-          for (j = 0; j < offsetFieldWidth; ++j) {
-            offset = (offset << 8) | stream.getByte();
-          }
-          for (j = 0; j < generationFieldWidth; ++j) {
-            generation = (generation << 8) | stream.getByte();
-          }
-          var entry = {};
-          entry.offset = offset;
-          entry.gen = generation;
-          switch (type) {
-            case 0:
-              entry.free = true;
-              break;
-            case 1:
-              entry.uncompressed = true;
-              break;
-            case 2:
-              break;
-            default:
-              error('Invalid XRef entry type: ' + type);
-          }
-          if (!this.entries[first + i]) {
-            this.entries[first + i] = entry;
-          }
-        }
-
-        streamState.entryNum = 0;
-        streamState.streamPos = stream.pos;
-        entryRanges.splice(0, 2);
-      }
-    },
-
-    indexObjects: function XRef_indexObjects() {
-      // Simple scan through the PDF content to find objects,
-      // trailers and XRef streams.
-      var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
-      var PERCENT = 0x25, LT = 0x3C;
-
-      function readToken(data, offset) {
-        var token = '', ch = data[offset];
-        while (ch !== LF && ch !== CR && ch !== LT) {
-          if (++offset >= data.length) {
-            break;
-          }
-          token += String.fromCharCode(ch);
-          ch = data[offset];
-        }
-        return token;
-      }
-      function skipUntil(data, offset, what) {
-        var length = what.length, dataLength = data.length;
-        var skipped = 0;
-        // finding byte sequence
-        while (offset < dataLength) {
-          var i = 0;
-          while (i < length && data[offset + i] === what[i]) {
-            ++i;
-          }
-          if (i >= length) {
-            break; // sequence found
-          }
-          offset++;
-          skipped++;
-        }
-        return skipped;
-      }
-      var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
-      var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
-      var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
-                                          101, 102]);
-      var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
-      var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
-
-      // Clear out any existing entries, since they may be bogus.
-      this.entries.length = 0;
-
-      var stream = this.stream;
-      stream.pos = 0;
-      var buffer = stream.getBytes();
-      var position = stream.start, length = buffer.length;
-      var trailers = [], xrefStms = [];
-      while (position < length) {
-        var ch = buffer[position];
-        if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
-          ++position;
-          continue;
-        }
-        if (ch === PERCENT) { // %-comment
-          do {
-            ++position;
-            if (position >= length) {
-              break;
-            }
-            ch = buffer[position];
-          } while (ch !== LF && ch !== CR);
-          continue;
-        }
-        var token = readToken(buffer, position);
-        var m;
-        if (token.indexOf('xref') === 0 &&
-            (token.length === 4 || /\s/.test(token[4]))) {
-          position += skipUntil(buffer, position, trailerBytes);
-          trailers.push(position);
-          position += skipUntil(buffer, position, startxrefBytes);
-        } else if ((m = objRegExp.exec(token))) {
-          if (typeof this.entries[m[1]] === 'undefined') {
-            this.entries[m[1]] = {
-              offset: position - stream.start,
-              gen: m[2] | 0,
-              uncompressed: true
-            };
-          }
-          var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
-          var content = buffer.subarray(position, position + contentLength);
-
-          // checking XRef stream suspect
-          // (it shall have '/XRef' and next char is not a letter)
-          var xrefTagOffset = skipUntil(content, 0, xrefBytes);
-          if (xrefTagOffset < contentLength &&
-              content[xrefTagOffset + 5] < 64) {
-            xrefStms.push(position - stream.start);
-            this.xrefstms[position - stream.start] = 1; // Avoid recursion
-          }
-
-          position += contentLength;
-        } else if (token.indexOf('trailer') === 0 &&
-                   (token.length === 7 || /\s/.test(token[7]))) {
-          trailers.push(position);
-          position += skipUntil(buffer, position, startxrefBytes);
-        } else {
-          position += token.length + 1;
-        }
-      }
-      // reading XRef streams
-      var i, ii;
-      for (i = 0, ii = xrefStms.length; i < ii; ++i) {
-        this.startXRefQueue.push(xrefStms[i]);
-        this.readXRef(/* recoveryMode */ true);
-      }
-      // finding main trailer
-      var dict;
-      for (i = 0, ii = trailers.length; i < ii; ++i) {
-        stream.pos = trailers[i];
-        var parser = new Parser(new Lexer(stream), true, this);
-        var obj = parser.getObj();
-        if (!isCmd(obj, 'trailer')) {
-          continue;
-        }
-        // read the trailer dictionary
-        if (!isDict(dict = parser.getObj())) {
-          continue;
-        }
-        // taking the first one with 'ID'
-        if (dict.has('ID')) {
-          return dict;
-        }
-      }
-      // no tailer with 'ID', taking last one (if exists)
-      if (dict) {
-        return dict;
-      }
-      // nothing helps
-      // calling error() would reject worker with an UnknownErrorException.
-      throw new InvalidPDFException('Invalid PDF structure');
-    },
-
-    readXRef: function XRef_readXRef(recoveryMode) {
-      var stream = this.stream;
-
-      try {
-        while (this.startXRefQueue.length) {
-          var startXRef = this.startXRefQueue[0];
-
-          stream.pos = startXRef + stream.start;
-
-          var parser = new Parser(new Lexer(stream), true, this);
-          var obj = parser.getObj();
-          var dict;
-
-          // Get dictionary
-          if (isCmd(obj, 'xref')) {
-            // Parse end-of-file XRef
-            dict = this.processXRefTable(parser);
-            if (!this.topDict) {
-              this.topDict = dict;
-            }
-
-            // Recursively get other XRefs 'XRefStm', if any
-            obj = dict.get('XRefStm');
-            if (isInt(obj)) {
-              var pos = obj;
-              // ignore previously loaded xref streams
-              // (possible infinite recursion)
-              if (!(pos in this.xrefstms)) {
-                this.xrefstms[pos] = 1;
-                this.startXRefQueue.push(pos);
-              }
-            }
-          } else if (isInt(obj)) {
-            // Parse in-stream XRef
-            if (!isInt(parser.getObj()) ||
-                !isCmd(parser.getObj(), 'obj') ||
-                !isStream(obj = parser.getObj())) {
-              error('Invalid XRef stream');
-            }
-            dict = this.processXRefStream(obj);
-            if (!this.topDict) {
-              this.topDict = dict;
-            }
-            if (!dict) {
-              error('Failed to read XRef stream');
-            }
-          } else {
-            error('Invalid XRef stream header');
-          }
-
-          // Recursively get previous dictionary, if any
-          obj = dict.get('Prev');
-          if (isInt(obj)) {
-            this.startXRefQueue.push(obj);
-          } else if (isRef(obj)) {
-            // The spec says Prev must not be a reference, i.e. "/Prev NNN"
-            // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
-            this.startXRefQueue.push(obj.num);
-          }
-
-          this.startXRefQueue.shift();
-        }
-
-        return this.topDict;
-      } catch (e) {
-        if (e instanceof MissingDataException) {
-          throw e;
-        }
-        info('(while reading XRef): ' + e);
-      }
-
-      if (recoveryMode) {
-        return;
-      }
-      throw new XRefParseException();
-    },
-
-    getEntry: function XRef_getEntry(i) {
-      var xrefEntry = this.entries[i];
-      if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
-        return xrefEntry;
-      }
-      return null;
-    },
-
-    fetchIfRef: function XRef_fetchIfRef(obj) {
-      if (!isRef(obj)) {
-        return obj;
-      }
-      return this.fetch(obj);
-    },
-
-    fetch: function XRef_fetch(ref, suppressEncryption) {
-      assert(isRef(ref), 'ref object is not a reference');
-      var num = ref.num;
-      if (num in this.cache) {
-        var cacheEntry = this.cache[num];
-        return cacheEntry;
-      }
-
-      var xrefEntry = this.getEntry(num);
-
-      // the referenced entry can be free
-      if (xrefEntry === null) {
-        return (this.cache[num] = null);
-      }
-
-      if (xrefEntry.uncompressed) {
-        xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
-      } else {
-        xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
-      }
-      if (isDict(xrefEntry)){
-        xrefEntry.objId = ref.toString();
-      } else if (isStream(xrefEntry)) {
-        xrefEntry.dict.objId = ref.toString();
-      }
-      return xrefEntry;
-    },
-
-    fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
-                                                       suppressEncryption) {
-      var gen = ref.gen;
-      var num = ref.num;
-      if (xrefEntry.gen !== gen) {
-        error('inconsistent generation in XRef');
-      }
-      var stream = this.stream.makeSubStream(xrefEntry.offset +
-                                             this.stream.start);
-      var parser = new Parser(new Lexer(stream), true, this);
-      var obj1 = parser.getObj();
-      var obj2 = parser.getObj();
-      var obj3 = parser.getObj();
-      if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
-          !isInt(obj2) || parseInt(obj2, 10) !== gen ||
-          !isCmd(obj3)) {
-        error('bad XRef entry');
-      }
-      if (!isCmd(obj3, 'obj')) {
-        // some bad PDFs use "obj1234" and really mean 1234
-        if (obj3.cmd.indexOf('obj') === 0) {
-          num = parseInt(obj3.cmd.substring(3), 10);
-          if (!isNaN(num)) {
-            return num;
-          }
-        }
-        error('bad XRef entry');
-      }
-      if (this.encrypt && !suppressEncryption) {
-        xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
-      } else {
-        xrefEntry = parser.getObj();
-      }
-      if (!isStream(xrefEntry)) {
-        this.cache[num] = xrefEntry;
-      }
-      return xrefEntry;
-    },
-
-    fetchCompressed: function XRef_fetchCompressed(xrefEntry,
-                                                   suppressEncryption) {
-      var tableOffset = xrefEntry.offset;
-      var stream = this.fetch(new Ref(tableOffset, 0));
-      if (!isStream(stream)) {
-        error('bad ObjStm stream');
-      }
-      var first = stream.dict.get('First');
-      var n = stream.dict.get('N');
-      if (!isInt(first) || !isInt(n)) {
-        error('invalid first and n parameters for ObjStm stream');
-      }
-      var parser = new Parser(new Lexer(stream), false, this);
-      parser.allowStreams = true;
-      var i, entries = [], num, nums = [];
-      // read the object numbers to populate cache
-      for (i = 0; i < n; ++i) {
-        num = parser.getObj();
-        if (!isInt(num)) {
-          error('invalid object number in the ObjStm stream: ' + num);
-        }
-        nums.push(num);
-        var offset = parser.getObj();
-        if (!isInt(offset)) {
-          error('invalid object offset in the ObjStm stream: ' + offset);
-        }
-      }
-      // read stream objects for cache
-      for (i = 0; i < n; ++i) {
-        entries.push(parser.getObj());
-        num = nums[i];
-        var entry = this.entries[num];
-        if (entry && entry.offset === tableOffset && entry.gen === i) {
-          this.cache[num] = entries[i];
-        }
-      }
-      xrefEntry = entries[xrefEntry.gen];
-      if (xrefEntry === undefined) {
-        error('bad XRef entry for compressed object');
-      }
-      return xrefEntry;
-    },
-
-    fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
-      if (!isRef(obj)) {
-        return Promise.resolve(obj);
-      }
-      return this.fetchAsync(obj);
-    },
-
-    fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
-      var streamManager = this.stream.manager;
-      var xref = this;
-      return new Promise(function tryFetch(resolve, reject) {
-        try {
-          resolve(xref.fetch(ref, suppressEncryption));
-        } catch (e) {
-          if (e instanceof MissingDataException) {
-            streamManager.requestRange(e.begin, e.end).then(function () {
-              tryFetch(resolve, reject);
-            }, reject);
-            return;
-          }
-          reject(e);
-        }
-      });
-    },
-
-    getCatalogObj: function XRef_getCatalogObj() {
-      return this.root;
-    }
-  };
-
-  return XRef;
-})();
-
-/**
- * A NameTree/NumberTree is like a Dict but has some advantageous properties,
- * see the specification (7.9.6 and 7.9.7) for additional details.
- * TODO: implement all the Dict functions and make this more efficient.
- */
-var NameOrNumberTree = (function NameOrNumberTreeClosure() {
-  function NameOrNumberTree(root, xref) {
-    throw new Error('Cannot initialize NameOrNumberTree.');
-  }
-
-  NameOrNumberTree.prototype = {
-    getAll: function NameOrNumberTree_getAll() {
-      var dict = Object.create(null);
-      if (!this.root) {
-        return dict;
-      }
-      var xref = this.xref;
-      // Reading Name/Number tree.
-      var processed = new RefSet();
-      processed.put(this.root);
-      var queue = [this.root];
-      while (queue.length > 0) {
-        var i, n;
-        var obj = xref.fetchIfRef(queue.shift());
-        if (!isDict(obj)) {
-          continue;
-        }
-        if (obj.has('Kids')) {
-          var kids = obj.get('Kids');
-          for (i = 0, n = kids.length; i < n; i++) {
-            var kid = kids[i];
-            assert(!processed.has(kid),
-                   'Duplicate entry in "' + this._type + '" tree.');
-            queue.push(kid);
-            processed.put(kid);
-          }
-          continue;
-        }
-        var entries = obj.get(this._type);
-        if (isArray(entries)) {
-          for (i = 0, n = entries.length; i < n; i += 2) {
-            dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
-          }
-        }
-      }
-      return dict;
-    },
-
-    get: function NameOrNumberTree_get(key) {
-      if (!this.root) {
-        return null;
-      }
-
-      var xref = this.xref;
-      var kidsOrEntries = xref.fetchIfRef(this.root);
-      var loopCount = 0;
-      var MAX_LEVELS = 10;
-      var l, r, m;
-
-      // Perform a binary search to quickly find the entry that
-      // contains the key we are looking for.
-      while (kidsOrEntries.has('Kids')) {
-        if (++loopCount > MAX_LEVELS) {
-          warn('Search depth limit reached for "' + this._type + '" tree.');
-          return null;
-        }
-
-        var kids = kidsOrEntries.get('Kids');
-        if (!isArray(kids)) {
-          return null;
-        }
-
-        l = 0;
-        r = kids.length - 1;
-        while (l <= r) {
-          m = (l + r) >> 1;
-          var kid = xref.fetchIfRef(kids[m]);
-          var limits = kid.get('Limits');
-
-          if (key < xref.fetchIfRef(limits[0])) {
-            r = m - 1;
-          } else if (key > xref.fetchIfRef(limits[1])) {
-            l = m + 1;
-          } else {
-            kidsOrEntries = xref.fetchIfRef(kids[m]);
-            break;
-          }
-        }
-        if (l > r) {
-          return null;
-        }
-      }
-
-      // If we get here, then we have found the right entry. Now go through the
-      // entries in the dictionary until we find the key we're looking for.
-      var entries = kidsOrEntries.get(this._type);
-      if (isArray(entries)) {
-        // Perform a binary search to reduce the lookup time.
-        l = 0;
-        r = entries.length - 2;
-        while (l <= r) {
-          // Check only even indices (0, 2, 4, ...) because the
-          // odd indices contain the actual data.
-          m = (l + r) & ~1;
-          var currentKey = xref.fetchIfRef(entries[m]);
-          if (key < currentKey) {
-            r = m - 2;
-          } else if (key > currentKey) {
-            l = m + 2;
-          } else {
-            return xref.fetchIfRef(entries[m + 1]);
-          }
-        }
-      }
-      return null;
-    }
-  };
-  return NameOrNumberTree;
-})();
-
-var NameTree = (function NameTreeClosure() {
-  function NameTree(root, xref) {
-    this.root = root;
-    this.xref = xref;
-    this._type = 'Names';
-  }
-
-  Util.inherit(NameTree, NameOrNumberTree, {});
-
-  return NameTree;
-})();
-
-var NumberTree = (function NumberTreeClosure() {
-  function NumberTree(root, xref) {
-    this.root = root;
-    this.xref = xref;
-    this._type = 'Nums';
-  }
-
-  Util.inherit(NumberTree, NameOrNumberTree, {});
-
-  return NumberTree;
-})();
-
-/**
- * "A PDF file can refer to the contents of another file by using a File
- * Specification (PDF 1.1)", see the spec (7.11) for more details.
- * NOTE: Only embedded files are supported (as part of the attachments support)
- * TODO: support the 'URL' file system (with caching if !/V), portable
- * collections attributes and related files (/RF)
- */
-var FileSpec = (function FileSpecClosure() {
-  function FileSpec(root, xref) {
-    if (!root || !isDict(root)) {
-      return;
-    }
-    this.xref = xref;
-    this.root = root;
-    if (root.has('FS')) {
-      this.fs = root.get('FS');
-    }
-    this.description = root.has('Desc') ?
-                         stringToPDFString(root.get('Desc')) :
-                         '';
-    if (root.has('RF')) {
-      warn('Related file specifications are not supported');
-    }
-    this.contentAvailable = true;
-    if (!root.has('EF')) {
-      this.contentAvailable = false;
-      warn('Non-embedded file specifications are not supported');
-    }
-  }
-
-  function pickPlatformItem(dict) {
-    // Look for the filename in this order:
-    // UF, F, Unix, Mac, DOS
-    if (dict.has('UF')) {
-      return dict.get('UF');
-    } else if (dict.has('F')) {
-      return dict.get('F');
-    } else if (dict.has('Unix')) {
-      return dict.get('Unix');
-    } else if (dict.has('Mac')) {
-      return dict.get('Mac');
-    } else if (dict.has('DOS')) {
-      return dict.get('DOS');
-    } else {
-      return null;
-    }
-  }
-
-  FileSpec.prototype = {
-    get filename() {
-      if (!this._filename && this.root) {
-        var filename = pickPlatformItem(this.root) || 'unnamed';
-        this._filename = stringToPDFString(filename).
-          replace(/\\\\/g, '\\').
-          replace(/\\\//g, '/').
-          replace(/\\/g, '/');
-      }
-      return this._filename;
-    },
-    get content() {
-      if (!this.contentAvailable) {
-        return null;
-      }
-      if (!this.contentRef && this.root) {
-        this.contentRef = pickPlatformItem(this.root.get('EF'));
-      }
-      var content = null;
-      if (this.contentRef) {
-        var xref = this.xref;
-        var fileObj = xref.fetchIfRef(this.contentRef);
-        if (fileObj && isStream(fileObj)) {
-          content = fileObj.getBytes();
-        } else {
-          warn('Embedded file specification points to non-existing/invalid ' +
-            'content');
-        }
-      } else {
-        warn('Embedded file specification does not have a content');
-      }
-      return content;
-    },
-    get serializable() {
-      return {
-        filename: this.filename,
-        content: this.content
-      };
-    }
-  };
-  return FileSpec;
-})();
-
-/**
- * A helper for loading missing data in object graphs. It traverses the graph
- * depth first and queues up any objects that have missing data. Once it has
- * has traversed as many objects that are available it attempts to bundle the
- * missing data requests and then resume from the nodes that weren't ready.
- *
- * NOTE: It provides protection from circular references by keeping track of
- * of loaded references. However, you must be careful not to load any graphs
- * that have references to the catalog or other pages since that will cause the
- * entire PDF document object graph to be traversed.
- */
-var ObjectLoader = (function() {
-  function mayHaveChildren(value) {
-    return isRef(value) || isDict(value) || isArray(value) || isStream(value);
-  }
-
-  function addChildren(node, nodesToVisit) {
-    var value;
-    if (isDict(node) || isStream(node)) {
-      var map;
-      if (isDict(node)) {
-        map = node.map;
-      } else {
-        map = node.dict.map;
-      }
-      for (var key in map) {
-        value = map[key];
-        if (mayHaveChildren(value)) {
-          nodesToVisit.push(value);
-        }
-      }
-    } else if (isArray(node)) {
-      for (var i = 0, ii = node.length; i < ii; i++) {
-        value = node[i];
-        if (mayHaveChildren(value)) {
-          nodesToVisit.push(value);
-        }
-      }
-    }
-  }
-
-  function ObjectLoader(obj, keys, xref) {
-    this.obj = obj;
-    this.keys = keys;
-    this.xref = xref;
-    this.refSet = null;
-    this.capability = null;
-  }
-
-  ObjectLoader.prototype = {
-    load: function ObjectLoader_load() {
-      var keys = this.keys;
-      this.capability = createPromiseCapability();
-      // Don't walk the graph if all the data is already loaded.
-      if (!(this.xref.stream instanceof ChunkedStream) ||
-          this.xref.stream.getMissingChunks().length === 0) {
-        this.capability.resolve();
-        return this.capability.promise;
-      }
-
-      this.refSet = new RefSet();
-      // Setup the initial nodes to visit.
-      var nodesToVisit = [];
-      for (var i = 0; i < keys.length; i++) {
-        nodesToVisit.push(this.obj[keys[i]]);
-      }
-
-      this._walk(nodesToVisit);
-      return this.capability.promise;
-    },
-
-    _walk: function ObjectLoader_walk(nodesToVisit) {
-      var nodesToRevisit = [];
-      var pendingRequests = [];
-      // DFS walk of the object graph.
-      while (nodesToVisit.length) {
-        var currentNode = nodesToVisit.pop();
-
-        // Only references or chunked streams can cause missing data exceptions.
-        if (isRef(currentNode)) {
-          // Skip nodes that have already been visited.
-          if (this.refSet.has(currentNode)) {
-            continue;
-          }
-          try {
-            var ref = currentNode;
-            this.refSet.put(ref);
-            currentNode = this.xref.fetch(currentNode);
-          } catch (e) {
-            if (!(e instanceof MissingDataException)) {
-              throw e;
-            }
-            nodesToRevisit.push(currentNode);
-            pendingRequests.push({ begin: e.begin, end: e.end });
-          }
-        }
-        if (currentNode && currentNode.getBaseStreams) {
-          var baseStreams = currentNode.getBaseStreams();
-          var foundMissingData = false;
-          for (var i = 0; i < baseStreams.length; i++) {
-            var stream = baseStreams[i];
-            if (stream.getMissingChunks && stream.getMissingChunks().length) {
-              foundMissingData = true;
-              pendingRequests.push({
-                begin: stream.start,
-                end: stream.end
-              });
-            }
-          }
-          if (foundMissingData) {
-            nodesToRevisit.push(currentNode);
-          }
-        }
-
-        addChildren(currentNode, nodesToVisit);
-      }
-
-      if (pendingRequests.length) {
-        this.xref.stream.manager.requestRanges(pendingRequests).then(
-            function pendingRequestCallback() {
-          nodesToVisit = nodesToRevisit;
-          for (var i = 0; i < nodesToRevisit.length; i++) {
-            var node = nodesToRevisit[i];
-            // Remove any reference nodes from the currrent refset so they
-            // aren't skipped when we revist them.
-            if (isRef(node)) {
-              this.refSet.remove(node);
-            }
-          }
-          this._walk(nodesToVisit);
-        }.bind(this), this.capability.reject);
-        return;
-      }
-      // Everything is loaded.
-      this.refSet = null;
-      this.capability.resolve();
-    }
-  };
-
-  return ObjectLoader;
-})();
-
-exports.Catalog = Catalog;
-exports.ObjectLoader = ObjectLoader;
-exports.XRef = XRef;
-}));
-
-
-(function (root, factory) {
-  {
     factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
       root.pdfjsCoreParser);
   }
 }(this, function (exports, sharedUtil, coreParser) {
 
 var error = sharedUtil.error;
 var EOF = coreParser.EOF;
 var Lexer = coreParser.Lexer;
@@ -35031,16 +33401,1597 @@ exports.PDFImage = PDFImage;
 
 // TODO refactor to remove dependency on colorspace.js
 coreColorSpace._setCoreImage(exports);
 }));
 
 
 (function (root, factory) {
   {
+    factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
+      root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
+      root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
+  }
+}(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
+                  coreChunkedStream, coreColorSpace) {
+
+var InvalidPDFException = sharedUtil.InvalidPDFException;
+var MissingDataException = sharedUtil.MissingDataException;
+var XRefParseException = sharedUtil.XRefParseException;
+var assert = sharedUtil.assert;
+var bytesToString = sharedUtil.bytesToString;
+var createPromiseCapability = sharedUtil.createPromiseCapability;
+var error = sharedUtil.error;
+var info = sharedUtil.info;
+var isArray = sharedUtil.isArray;
+var isInt = sharedUtil.isInt;
+var isString = sharedUtil.isString;
+var shadow = sharedUtil.shadow;
+var stringToPDFString = sharedUtil.stringToPDFString;
+var stringToUTF8String = sharedUtil.stringToUTF8String;
+var warn = sharedUtil.warn;
+var isValidUrl = sharedUtil.isValidUrl;
+var Util = sharedUtil.Util;
+var Ref = corePrimitives.Ref;
+var RefSet = corePrimitives.RefSet;
+var RefSetCache = corePrimitives.RefSetCache;
+var isName = corePrimitives.isName;
+var isCmd = corePrimitives.isCmd;
+var isDict = corePrimitives.isDict;
+var isRef = corePrimitives.isRef;
+var isStream = corePrimitives.isStream;
+var CipherTransformFactory = coreCrypto.CipherTransformFactory;
+var Lexer = coreParser.Lexer;
+var Parser = coreParser.Parser;
+var ChunkedStream = coreChunkedStream.ChunkedStream;
+var ColorSpace = coreColorSpace.ColorSpace;
+
+var Catalog = (function CatalogClosure() {
+  function Catalog(pdfManager, xref, pageFactory) {
+    this.pdfManager = pdfManager;
+    this.xref = xref;
+    this.catDict = xref.getCatalogObj();
+    this.fontCache = new RefSetCache();
+    assert(isDict(this.catDict),
+      'catalog object is not a dictionary');
+
+    // TODO refactor to move getPage() to the PDFDocument.
+    this.pageFactory = pageFactory;
+    this.pagePromises = [];
+  }
+
+  Catalog.prototype = {
+    get metadata() {
+      var streamRef = this.catDict.getRaw('Metadata');
+      if (!isRef(streamRef)) {
+        return shadow(this, 'metadata', null);
+      }
+
+      var encryptMetadata = (!this.xref.encrypt ? false :
+                             this.xref.encrypt.encryptMetadata);
+
+      var stream = this.xref.fetch(streamRef, !encryptMetadata);
+      var metadata;
+      if (stream && isDict(stream.dict)) {
+        var type = stream.dict.get('Type');
+        var subtype = stream.dict.get('Subtype');
+
+        if (isName(type) && isName(subtype) &&
+            type.name === 'Metadata' && subtype.name === 'XML') {
+          // XXX: This should examine the charset the XML document defines,
+          // however since there are currently no real means to decode
+          // arbitrary charsets, let's just hope that the author of the PDF
+          // was reasonable enough to stick with the XML default charset,
+          // which is UTF-8.
+          try {
+            metadata = stringToUTF8String(bytesToString(stream.getBytes()));
+          } catch (e) {
+            info('Skipping invalid metadata.');
+          }
+        }
+      }
+
+      return shadow(this, 'metadata', metadata);
+    },
+    get toplevelPagesDict() {
+      var pagesObj = this.catDict.get('Pages');
+      assert(isDict(pagesObj), 'invalid top-level pages dictionary');
+      // shadow the prototype getter
+      return shadow(this, 'toplevelPagesDict', pagesObj);
+    },
+    get documentOutline() {
+      var obj = null;
+      try {
+        obj = this.readDocumentOutline();
+      } catch (ex) {
+        if (ex instanceof MissingDataException) {
+          throw ex;
+        }
+        warn('Unable to read document outline');
+      }
+      return shadow(this, 'documentOutline', obj);
+    },
+    readDocumentOutline: function Catalog_readDocumentOutline() {
+      var obj = this.catDict.get('Outlines');
+      if (!isDict(obj)) {
+        return null;
+      }
+      obj = obj.getRaw('First');
+      if (!isRef(obj)) {
+        return null;
+      }
+      var root = { items: [] };
+      var queue = [{obj: obj, parent: root}];
+      // To avoid recursion, keep track of the already processed items.
+      var processed = new RefSet();
+      processed.put(obj);
+      var xref = this.xref, blackColor = new Uint8Array(3);
+
+      while (queue.length > 0) {
+        var i = queue.shift();
+        var outlineDict = xref.fetchIfRef(i.obj);
+        if (outlineDict === null) {
+          continue;
+        }
+        assert(outlineDict.has('Title'), 'Invalid outline item');
+
+        var actionDict = outlineDict.get('A'), dest = null, url = null;
+        if (actionDict) {
+          var destEntry = actionDict.get('D');
+          if (destEntry) {
+            dest = destEntry;
+          } else {
+            var uriEntry = actionDict.get('URI');
+            if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
+              url = uriEntry;
+            }
+          }
+        } else if (outlineDict.has('Dest')) {
+          dest = outlineDict.getRaw('Dest');
+          if (isName(dest)) {
+            dest = dest.name;
+          }
+        }
+        var title = outlineDict.get('Title');
+        var flags = outlineDict.get('F') || 0;
+
+        var color = outlineDict.get('C'), rgbColor = blackColor;
+        // We only need to parse the color when it's valid, and non-default.
+        if (isArray(color) && color.length === 3 &&
+            (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
+          rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
+        }
+        var outlineItem = {
+          dest: dest,
+          url: url,
+          title: stringToPDFString(title),
+          color: rgbColor,
+          count: outlineDict.get('Count'),
+          bold: !!(flags & 2),
+          italic: !!(flags & 1),
+          items: []
+        };
+        i.parent.items.push(outlineItem);
+        obj = outlineDict.getRaw('First');
+        if (isRef(obj) && !processed.has(obj)) {
+          queue.push({obj: obj, parent: outlineItem});
+          processed.put(obj);
+        }
+        obj = outlineDict.getRaw('Next');
+        if (isRef(obj) && !processed.has(obj)) {
+          queue.push({obj: obj, parent: i.parent});
+          processed.put(obj);
+        }
+      }
+      return (root.items.length > 0 ? root.items : null);
+    },
+    get numPages() {
+      var obj = this.toplevelPagesDict.get('Count');
+      assert(
+        isInt(obj),
+        'page count in top level pages object is not an integer'
+      );
+      // shadow the prototype getter
+      return shadow(this, 'num', obj);
+    },
+    get destinations() {
+      function fetchDestination(dest) {
+        return isDict(dest) ? dest.get('D') : dest;
+      }
+
+      var xref = this.xref;
+      var dests = {}, nameTreeRef, nameDictionaryRef;
+      var obj = this.catDict.get('Names');
+      if (obj && obj.has('Dests')) {
+        nameTreeRef = obj.getRaw('Dests');
+      } else if (this.catDict.has('Dests')) {
+        nameDictionaryRef = this.catDict.get('Dests');
+      }
+
+      if (nameDictionaryRef) {
+        // reading simple destination dictionary
+        obj = nameDictionaryRef;
+        obj.forEach(function catalogForEach(key, value) {
+          if (!value) {
+            return;
+          }
+          dests[key] = fetchDestination(value);
+        });
+      }
+      if (nameTreeRef) {
+        var nameTree = new NameTree(nameTreeRef, xref);
+        var names = nameTree.getAll();
+        for (var name in names) {
+          dests[name] = fetchDestination(names[name]);
+        }
+      }
+      return shadow(this, 'destinations', dests);
+    },
+    getDestination: function Catalog_getDestination(destinationId) {
+      function fetchDestination(dest) {
+        return isDict(dest) ? dest.get('D') : dest;
+      }
+
+      var xref = this.xref;
+      var dest = null, nameTreeRef, nameDictionaryRef;
+      var obj = this.catDict.get('Names');
+      if (obj && obj.has('Dests')) {
+        nameTreeRef = obj.getRaw('Dests');
+      } else if (this.catDict.has('Dests')) {
+        nameDictionaryRef = this.catDict.get('Dests');
+      }
+
+      if (nameDictionaryRef) { // Simple destination dictionary.
+        var value = nameDictionaryRef.get(destinationId);
+        if (value) {
+          dest = fetchDestination(value);
+        }
+      }
+      if (nameTreeRef) {
+        var nameTree = new NameTree(nameTreeRef, xref);
+        dest = fetchDestination(nameTree.get(destinationId));
+      }
+      return dest;
+    },
+
+    get pageLabels() {
+      var obj = null;
+      try {
+        obj = this.readPageLabels();
+      } catch (ex) {
+        if (ex instanceof MissingDataException) {
+          throw ex;
+        }
+        warn('Unable to read page labels.');
+      }
+      return shadow(this, 'pageLabels', obj);
+    },
+    readPageLabels: function Catalog_readPageLabels() {
+      var obj = this.catDict.getRaw('PageLabels');
+      if (!obj) {
+        return null;
+      }
+      var pageLabels = new Array(this.numPages);
+      var style = null;
+      var prefix = '';
+      var start = 1;
+
+      var numberTree = new NumberTree(obj, this.xref);
+      var nums = numberTree.getAll();
+      var currentLabel = '', currentIndex = 1;
+
+      for (var i = 0, ii = this.numPages; i < ii; i++) {
+        if (i in nums) {
+          var labelDict = nums[i];
+          assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
+
+          var type = labelDict.get('Type');
+          assert(!type || (isName(type) && type.name === 'PageLabel'),
+                 'Invalid type in PageLabel dictionary.');
+
+          var s = labelDict.get('S');
+          assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
+          style = (s ? s.name : null);
+
+          prefix = labelDict.get('P') || '';
+          assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
+
+          start = labelDict.get('St') || 1;
+          assert(isInt(start), 'Invalid start in PageLabel dictionary.');
+          currentIndex = start;
+        }
+
+        switch (style) {
+          case 'D':
+            currentLabel = currentIndex;
+            break;
+          case 'R':
+          case 'r':
+            currentLabel = Util.toRoman(currentIndex, style === 'r');
+            break;
+          case 'A':
+          case 'a':
+            var LIMIT = 26; // Use only the characters A--Z, or a--z.
+            var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
+
+            var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
+            var letterIndex = currentIndex - 1;
+            var character = String.fromCharCode(baseCharCode +
+                                                (letterIndex % LIMIT));
+            var charBuf = [];
+            for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
+              charBuf.push(character);
+            }
+            currentLabel = charBuf.join('');
+            break;
+          default:
+            assert(!style,
+                   'Invalid style "' + style + '" in PageLabel dictionary.');
+        }
+        pageLabels[i] = prefix + currentLabel;
+
+        currentLabel = '';
+        currentIndex++;
+      }
+      return pageLabels;
+    },
+
+    get attachments() {
+      var xref = this.xref;
+      var attachments = null, nameTreeRef;
+      var obj = this.catDict.get('Names');
+      if (obj) {
+        nameTreeRef = obj.getRaw('EmbeddedFiles');
+      }
+
+      if (nameTreeRef) {
+        var nameTree = new NameTree(nameTreeRef, xref);
+        var names = nameTree.getAll();
+        for (var name in names) {
+          var fs = new FileSpec(names[name], xref);
+          if (!attachments) {
+            attachments = Object.create(null);
+          }
+          attachments[stringToPDFString(name)] = fs.serializable;
+        }
+      }
+      return shadow(this, 'attachments', attachments);
+    },
+    get javaScript() {
+      var xref = this.xref;
+      var obj = this.catDict.get('Names');
+
+      var javaScript = [];
+      function appendIfJavaScriptDict(jsDict) {
+        var type = jsDict.get('S');
+        if (!isName(type) || type.name !== 'JavaScript') {
+          return;
+        }
+        var js = jsDict.get('JS');
+        if (isStream(js)) {
+          js = bytesToString(js.getBytes());
+        } else if (!isString(js)) {
+          return;
+        }
+        javaScript.push(stringToPDFString(js));
+      }
+      if (obj && obj.has('JavaScript')) {
+        var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
+        var names = nameTree.getAll();
+        for (var name in names) {
+          // We don't really use the JavaScript right now. This code is
+          // defensive so we don't cause errors on document load.
+          var jsDict = names[name];
+          if (isDict(jsDict)) {
+            appendIfJavaScriptDict(jsDict);
+          }
+        }
+      }
+
+      // Append OpenAction actions to javaScript array
+      var openactionDict = this.catDict.get('OpenAction');
+      if (isDict(openactionDict, 'Action')) {
+        var actionType = openactionDict.get('S');
+        if (isName(actionType) && actionType.name === 'Named') {
+          // The named Print action is not a part of the PDF 1.7 specification,
+          // but is supported by many PDF readers/writers (including Adobe's).
+          var action = openactionDict.get('N');
+          if (isName(action) && action.name === 'Print') {
+            javaScript.push('print({});');
+          }
+        } else {
+          appendIfJavaScriptDict(openactionDict);
+        }
+      }
+
+      return shadow(this, 'javaScript', javaScript);
+    },
+
+    cleanup: function Catalog_cleanup() {
+      var promises = [];
+      this.fontCache.forEach(function (promise) {
+        promises.push(promise);
+      });
+      return Promise.all(promises).then(function (translatedFonts) {
+        for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
+          var font = translatedFonts[i].dict;
+          delete font.translated;
+        }
+        this.fontCache.clear();
+      }.bind(this));
+    },
+
+    getPage: function Catalog_getPage(pageIndex) {
+      if (!(pageIndex in this.pagePromises)) {
+        this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
+          function (a) {
+            var dict = a[0];
+            var ref = a[1];
+            return this.pageFactory.createPage(pageIndex, dict, ref,
+                                               this.fontCache);
+          }.bind(this)
+        );
+      }
+      return this.pagePromises[pageIndex];
+    },
+
+    getPageDict: function Catalog_getPageDict(pageIndex) {
+      var capability = createPromiseCapability();
+      var nodesToVisit = [this.catDict.getRaw('Pages')];
+      var currentPageIndex = 0;
+      var xref = this.xref;
+      var checkAllKids = false;
+
+      function next() {
+        while (nodesToVisit.length) {
+          var currentNode = nodesToVisit.pop();
+
+          if (isRef(currentNode)) {
+            xref.fetchAsync(currentNode).then(function (obj) {
+              if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
+                if (pageIndex === currentPageIndex) {
+                  capability.resolve([obj, currentNode]);
+                } else {
+                  currentPageIndex++;
+                  next();
+                }
+                return;
+              }
+              nodesToVisit.push(obj);
+              next();
+            }, capability.reject);
+            return;
+          }
+
+          // Must be a child page dictionary.
+          assert(
+            isDict(currentNode),
+            'page dictionary kid reference points to wrong type of object'
+          );
+          var count = currentNode.get('Count');
+          // If the current node doesn't have any children, avoid getting stuck
+          // in an empty node further down in the tree (see issue5644.pdf).
+          if (count === 0) {
+            checkAllKids = true;
+          }
+          // Skip nodes where the page can't be.
+          if (currentPageIndex + count <= pageIndex) {
+            currentPageIndex += count;
+            continue;
+          }
+
+          var kids = currentNode.get('Kids');
+          assert(isArray(kids), 'page dictionary kids object is not an array');
+          if (!checkAllKids && count === kids.length) {
+            // Nodes that don't have the page have been skipped and this is the
+            // bottom of the tree which means the page requested must be a
+            // descendant of this pages node. Ideally we would just resolve the
+            // promise with the page ref here, but there is the case where more
+            // pages nodes could link to single a page (see issue 3666 pdf). To
+            // handle this push it back on the queue so if it is a pages node it
+            // will be descended into.
+            nodesToVisit = [kids[pageIndex - currentPageIndex]];
+            currentPageIndex = pageIndex;
+            continue;
+          } else {
+            for (var last = kids.length - 1; last >= 0; last--) {
+              nodesToVisit.push(kids[last]);
+            }
+          }
+        }
+        capability.reject('Page index ' + pageIndex + ' not found.');
+      }
+      next();
+      return capability.promise;
+    },
+
+    getPageIndex: function Catalog_getPageIndex(ref) {
+      // The page tree nodes have the count of all the leaves below them. To get
+      // how many pages are before we just have to walk up the tree and keep
+      // adding the count of siblings to the left of the node.
+      var xref = this.xref;
+      function pagesBeforeRef(kidRef) {
+        var total = 0;
+        var parentRef;
+        return xref.fetchAsync(kidRef).then(function (node) {
+          if (!node) {
+            return null;
+          }
+          parentRef = node.getRaw('Parent');
+          return node.getAsync('Parent');
+        }).then(function (parent) {
+          if (!parent) {
+            return null;
+          }
+          return parent.getAsync('Kids');
+        }).then(function (kids) {
+          if (!kids) {
+            return null;
+          }
+          var kidPromises = [];
+          var found = false;
+          for (var i = 0; i < kids.length; i++) {
+            var kid = kids[i];
+            assert(isRef(kid), 'kids must be a ref');
+            if (kid.num === kidRef.num) {
+              found = true;
+              break;
+            }
+            kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
+              if (kid.has('Count')) {
+                var count = kid.get('Count');
+                total += count;
+              } else { // page leaf node
+                total++;
+              }
+            }));
+          }
+          if (!found) {
+            error('kid ref not found in parents kids');
+          }
+          return Promise.all(kidPromises).then(function () {
+            return [total, parentRef];
+          });
+        });
+      }
+
+      var total = 0;
+      function next(ref) {
+        return pagesBeforeRef(ref).then(function (args) {
+          if (!args) {
+            return total;
+          }
+          var count = args[0];
+          var parentRef = args[1];
+          total += count;
+          return next(parentRef);
+        });
+      }
+
+      return next(ref);
+    }
+  };
+
+  return Catalog;
+})();
+
+var XRef = (function XRefClosure() {
+  function XRef(stream, password) {
+    this.stream = stream;
+    this.entries = [];
+    this.xrefstms = Object.create(null);
+    // prepare the XRef cache
+    this.cache = [];
+    this.password = password;
+    this.stats = {
+      streamTypes: [],
+      fontTypes: []
+    };
+  }
+
+  XRef.prototype = {
+    setStartXRef: function XRef_setStartXRef(startXRef) {
+      // Store the starting positions of xref tables as we process them
+      // so we can recover from missing data errors
+      this.startXRefQueue = [startXRef];
+    },
+
+    parse: function XRef_parse(recoveryMode) {
+      var trailerDict;
+      if (!recoveryMode) {
+        trailerDict = this.readXRef();
+      } else {
+        warn('Indexing all PDF objects');
+        trailerDict = this.indexObjects();
+      }
+      trailerDict.assignXref(this);
+      this.trailer = trailerDict;
+      var encrypt = trailerDict.get('Encrypt');
+      if (encrypt) {
+        var ids = trailerDict.get('ID');
+        var fileId = (ids && ids.length) ? ids[0] : '';
+        this.encrypt = new CipherTransformFactory(encrypt, fileId,
+                                                  this.password);
+      }
+
+      // get the root dictionary (catalog) object
+      if (!(this.root = trailerDict.get('Root'))) {
+        error('Invalid root reference');
+      }
+    },
+
+    processXRefTable: function XRef_processXRefTable(parser) {
+      if (!('tableState' in this)) {
+        // Stores state of the table as we process it so we can resume
+        // from middle of table in case of missing data error
+        this.tableState = {
+          entryNum: 0,
+          streamPos: parser.lexer.stream.pos,
+          parserBuf1: parser.buf1,
+          parserBuf2: parser.buf2
+        };
+      }
+
+      var obj = this.readXRefTable(parser);
+
+      // Sanity check
+      if (!isCmd(obj, 'trailer')) {
+        error('Invalid XRef table: could not find trailer dictionary');
+      }
+      // Read trailer dictionary, e.g.
+      // trailer
+      //    << /Size 22
+      //      /Root 20R
+      //      /Info 10R
+      //      /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
+      //    >>
+      // The parser goes through the entire stream << ... >> and provides
+      // a getter interface for the key-value table
+      var dict = parser.getObj();
+
+      // The pdflib PDF generator can generate a nested trailer dictionary
+      if (!isDict(dict) && dict.dict) {
+        dict = dict.dict;
+      }
+      if (!isDict(dict)) {
+        error('Invalid XRef table: could not parse trailer dictionary');
+      }
+      delete this.tableState;
+
+      return dict;
+    },
+
+    readXRefTable: function XRef_readXRefTable(parser) {
+      // Example of cross-reference table:
+      // xref
+      // 0 1                    <-- subsection header (first obj #, obj count)
+      // 0000000000 65535 f     <-- actual object (offset, generation #, f/n)
+      // 23 2                   <-- subsection header ... and so on ...
+      // 0000025518 00002 n
+      // 0000025635 00000 n
+      // trailer
+      // ...
+
+      var stream = parser.lexer.stream;
+      var tableState = this.tableState;
+      stream.pos = tableState.streamPos;
+      parser.buf1 = tableState.parserBuf1;
+      parser.buf2 = tableState.parserBuf2;
+
+      // Outer loop is over subsection headers
+      var obj;
+
+      while (true) {
+        if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
+          if (isCmd(obj = parser.getObj(), 'trailer')) {
+            break;
+          }
+          tableState.firstEntryNum = obj;
+          tableState.entryCount = parser.getObj();
+        }
+
+        var first = tableState.firstEntryNum;
+        var count = tableState.entryCount;
+        if (!isInt(first) || !isInt(count)) {
+          error('Invalid XRef table: wrong types in subsection header');
+        }
+        // Inner loop is over objects themselves
+        for (var i = tableState.entryNum; i < count; i++) {
+          tableState.streamPos = stream.pos;
+          tableState.entryNum = i;
+          tableState.parserBuf1 = parser.buf1;
+          tableState.parserBuf2 = parser.buf2;
+
+          var entry = {};
+          entry.offset = parser.getObj();
+          entry.gen = parser.getObj();
+          var type = parser.getObj();
+
+          if (isCmd(type, 'f')) {
+            entry.free = true;
+          } else if (isCmd(type, 'n')) {
+            entry.uncompressed = true;
+          }
+
+          // Validate entry obj
+          if (!isInt(entry.offset) || !isInt(entry.gen) ||
+              !(entry.free || entry.uncompressed)) {
+            error('Invalid entry in XRef subsection: ' + first + ', ' + count);
+          }
+
+          if (!this.entries[i + first]) {
+            this.entries[i + first] = entry;
+          }
+        }
+
+        tableState.entryNum = 0;
+        tableState.streamPos = stream.pos;
+        tableState.parserBuf1 = parser.buf1;
+        tableState.parserBuf2 = parser.buf2;
+        delete tableState.firstEntryNum;
+        delete tableState.entryCount;
+      }
+
+      // Per issue 3248: hp scanners generate bad XRef
+      if (first === 1 && this.entries[1] && this.entries[1].free) {
+        // shifting the entries
+        this.entries.shift();
+      }
+
+      // Sanity check: as per spec, first object must be free
+      if (this.entries[0] && !this.entries[0].free) {
+        error('Invalid XRef table: unexpected first object');
+      }
+      return obj;
+    },
+
+    processXRefStream: function XRef_processXRefStream(stream) {
+      if (!('streamState' in this)) {
+        // Stores state of the stream as we process it so we can resume
+        // from middle of stream in case of missing data error
+        var streamParameters = stream.dict;
+        var byteWidths = streamParameters.get('W');
+        var range = streamParameters.get('Index');
+        if (!range) {
+          range = [0, streamParameters.get('Size')];
+        }
+
+        this.streamState = {
+          entryRanges: range,
+          byteWidths: byteWidths,
+          entryNum: 0,
+          streamPos: stream.pos
+        };
+      }
+      this.readXRefStream(stream);
+      delete this.streamState;
+
+      return stream.dict;
+    },
+
+    readXRefStream: function XRef_readXRefStream(stream) {
+      var i, j;
+      var streamState = this.streamState;
+      stream.pos = streamState.streamPos;
+
+      var byteWidths = streamState.byteWidths;
+      var typeFieldWidth = byteWidths[0];
+      var offsetFieldWidth = byteWidths[1];
+      var generationFieldWidth = byteWidths[2];
+
+      var entryRanges = streamState.entryRanges;
+      while (entryRanges.length > 0) {
+        var first = entryRanges[0];
+        var n = entryRanges[1];
+
+        if (!isInt(first) || !isInt(n)) {
+          error('Invalid XRef range fields: ' + first + ', ' + n);
+        }
+        if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
+            !isInt(generationFieldWidth)) {
+          error('Invalid XRef entry fields length: ' + first + ', ' + n);
+        }
+        for (i = streamState.entryNum; i < n; ++i) {
+          streamState.entryNum = i;
+          streamState.streamPos = stream.pos;
+
+          var type = 0, offset = 0, generation = 0;
+          for (j = 0; j < typeFieldWidth; ++j) {
+            type = (type << 8) | stream.getByte();
+          }
+          // if type field is absent, its default value is 1
+          if (typeFieldWidth === 0) {
+            type = 1;
+          }
+          for (j = 0; j < offsetFieldWidth; ++j) {
+            offset = (offset << 8) | stream.getByte();
+          }
+          for (j = 0; j < generationFieldWidth; ++j) {
+            generation = (generation << 8) | stream.getByte();
+          }
+          var entry = {};
+          entry.offset = offset;
+          entry.gen = generation;
+          switch (type) {
+            case 0:
+              entry.free = true;
+              break;
+            case 1:
+              entry.uncompressed = true;
+              break;
+            case 2:
+              break;
+            default:
+              error('Invalid XRef entry type: ' + type);
+          }
+          if (!this.entries[first + i]) {
+            this.entries[first + i] = entry;
+          }
+        }
+
+        streamState.entryNum = 0;
+        streamState.streamPos = stream.pos;
+        entryRanges.splice(0, 2);
+      }
+    },
+
+    indexObjects: function XRef_indexObjects() {
+      // Simple scan through the PDF content to find objects,
+      // trailers and XRef streams.
+      var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
+      var PERCENT = 0x25, LT = 0x3C;
+
+      function readToken(data, offset) {
+        var token = '', ch = data[offset];
+        while (ch !== LF && ch !== CR && ch !== LT) {
+          if (++offset >= data.length) {
+            break;
+          }
+          token += String.fromCharCode(ch);
+          ch = data[offset];
+        }
+        return token;
+      }
+      function skipUntil(data, offset, what) {
+        var length = what.length, dataLength = data.length;
+        var skipped = 0;
+        // finding byte sequence
+        while (offset < dataLength) {
+          var i = 0;
+          while (i < length && data[offset + i] === what[i]) {
+            ++i;
+          }
+          if (i >= length) {
+            break; // sequence found
+          }
+          offset++;
+          skipped++;
+        }
+        return skipped;
+      }
+      var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
+      var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
+      var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
+                                          101, 102]);
+      var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
+      var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
+
+      // Clear out any existing entries, since they may be bogus.
+      this.entries.length = 0;
+
+      var stream = this.stream;
+      stream.pos = 0;
+      var buffer = stream.getBytes();
+      var position = stream.start, length = buffer.length;
+      var trailers = [], xrefStms = [];
+      while (position < length) {
+        var ch = buffer[position];
+        if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
+          ++position;
+          continue;
+        }
+        if (ch === PERCENT) { // %-comment
+          do {
+            ++position;
+            if (position >= length) {
+              break;
+            }
+            ch = buffer[position];
+          } while (ch !== LF && ch !== CR);
+          continue;
+        }
+        var token = readToken(buffer, position);
+        var m;
+        if (token.indexOf('xref') === 0 &&
+            (token.length === 4 || /\s/.test(token[4]))) {
+          position += skipUntil(buffer, position, trailerBytes);
+          trailers.push(position);
+          position += skipUntil(buffer, position, startxrefBytes);
+        } else if ((m = objRegExp.exec(token))) {
+          if (typeof this.entries[m[1]] === 'undefined') {
+            this.entries[m[1]] = {
+              offset: position - stream.start,
+              gen: m[2] | 0,
+              uncompressed: true
+            };
+          }
+          var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
+          var content = buffer.subarray(position, position + contentLength);
+
+          // checking XRef stream suspect
+          // (it shall have '/XRef' and next char is not a letter)
+          var xrefTagOffset = skipUntil(content, 0, xrefBytes);
+          if (xrefTagOffset < contentLength &&
+              content[xrefTagOffset + 5] < 64) {
+            xrefStms.push(position - stream.start);
+            this.xrefstms[position - stream.start] = 1; // Avoid recursion
+          }
+
+          position += contentLength;
+        } else if (token.indexOf('trailer') === 0 &&
+                   (token.length === 7 || /\s/.test(token[7]))) {
+          trailers.push(position);
+          position += skipUntil(buffer, position, startxrefBytes);
+        } else {
+          position += token.length + 1;
+        }
+      }
+      // reading XRef streams
+      var i, ii;
+      for (i = 0, ii = xrefStms.length; i < ii; ++i) {
+        this.startXRefQueue.push(xrefStms[i]);
+        this.readXRef(/* recoveryMode */ true);
+      }
+      // finding main trailer
+      var dict;
+      for (i = 0, ii = trailers.length; i < ii; ++i) {
+        stream.pos = trailers[i];
+        var parser = new Parser(new Lexer(stream), true, this);
+        var obj = parser.getObj();
+        if (!isCmd(obj, 'trailer')) {
+          continue;
+        }
+        // read the trailer dictionary
+        if (!isDict(dict = parser.getObj())) {
+          continue;
+        }
+        // taking the first one with 'ID'
+        if (dict.has('ID')) {
+          return dict;
+        }
+      }
+      // no tailer with 'ID', taking last one (if exists)
+      if (dict) {
+        return dict;
+      }
+      // nothing helps
+      // calling error() would reject worker with an UnknownErrorException.
+      throw new InvalidPDFException('Invalid PDF structure');
+    },
+
+    readXRef: function XRef_readXRef(recoveryMode) {
+      var stream = this.stream;
+
+      try {
+        while (this.startXRefQueue.length) {
+          var startXRef = this.startXRefQueue[0];
+
+          stream.pos = startXRef + stream.start;
+
+          var parser = new Parser(new Lexer(stream), true, this);
+          var obj = parser.getObj();
+          var dict;
+
+          // Get dictionary
+          if (isCmd(obj, 'xref')) {
+            // Parse end-of-file XRef
+            dict = this.processXRefTable(parser);
+            if (!this.topDict) {
+              this.topDict = dict;
+            }
+
+            // Recursively get other XRefs 'XRefStm', if any
+            obj = dict.get('XRefStm');
+            if (isInt(obj)) {
+              var pos = obj;
+              // ignore previously loaded xref streams
+              // (possible infinite recursion)
+              if (!(pos in this.xrefstms)) {
+                this.xrefstms[pos] = 1;
+                this.startXRefQueue.push(pos);
+              }
+            }
+          } else if (isInt(obj)) {
+            // Parse in-stream XRef
+            if (!isInt(parser.getObj()) ||
+                !isCmd(parser.getObj(), 'obj') ||
+                !isStream(obj = parser.getObj())) {
+              error('Invalid XRef stream');
+            }
+            dict = this.processXRefStream(obj);
+            if (!this.topDict) {
+              this.topDict = dict;
+            }
+            if (!dict) {
+              error('Failed to read XRef stream');
+            }
+          } else {
+            error('Invalid XRef stream header');
+          }
+
+          // Recursively get previous dictionary, if any
+          obj = dict.get('Prev');
+          if (isInt(obj)) {
+            this.startXRefQueue.push(obj);
+          } else if (isRef(obj)) {
+            // The spec says Prev must not be a reference, i.e. "/Prev NNN"
+            // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
+            this.startXRefQueue.push(obj.num);
+          }
+
+          this.startXRefQueue.shift();
+        }
+
+        return this.topDict;
+      } catch (e) {
+        if (e instanceof MissingDataException) {
+          throw e;
+        }
+        info('(while reading XRef): ' + e);
+      }
+
+      if (recoveryMode) {
+        return;
+      }
+      throw new XRefParseException();
+    },
+
+    getEntry: function XRef_getEntry(i) {
+      var xrefEntry = this.entries[i];
+      if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
+        return xrefEntry;
+      }
+      return null;
+    },
+
+    fetchIfRef: function XRef_fetchIfRef(obj) {
+      if (!isRef(obj)) {
+        return obj;
+      }
+      return this.fetch(obj);
+    },
+
+    fetch: function XRef_fetch(ref, suppressEncryption) {
+      assert(isRef(ref), 'ref object is not a reference');
+      var num = ref.num;
+      if (num in this.cache) {
+        var cacheEntry = this.cache[num];
+        return cacheEntry;
+      }
+
+      var xrefEntry = this.getEntry(num);
+
+      // the referenced entry can be free
+      if (xrefEntry === null) {
+        return (this.cache[num] = null);
+      }
+
+      if (xrefEntry.uncompressed) {
+        xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
+      } else {
+        xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
+      }
+      if (isDict(xrefEntry)){
+        xrefEntry.objId = ref.toString();
+      } else if (isStream(xrefEntry)) {
+        xrefEntry.dict.objId = ref.toString();
+      }
+      return xrefEntry;
+    },
+
+    fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
+                                                       suppressEncryption) {
+      var gen = ref.gen;
+      var num = ref.num;
+      if (xrefEntry.gen !== gen) {
+        error('inconsistent generation in XRef');
+      }
+      var stream = this.stream.makeSubStream(xrefEntry.offset +
+                                             this.stream.start);
+      var parser = new Parser(new Lexer(stream), true, this);
+      var obj1 = parser.getObj();
+      var obj2 = parser.getObj();
+      var obj3 = parser.getObj();
+      if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
+          !isInt(obj2) || parseInt(obj2, 10) !== gen ||
+          !isCmd(obj3)) {
+        error('bad XRef entry');
+      }
+      if (!isCmd(obj3, 'obj')) {
+        // some bad PDFs use "obj1234" and really mean 1234
+        if (obj3.cmd.indexOf('obj') === 0) {
+          num = parseInt(obj3.cmd.substring(3), 10);
+          if (!isNaN(num)) {
+            return num;
+          }
+        }
+        error('bad XRef entry');
+      }
+      if (this.encrypt && !suppressEncryption) {
+        xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
+      } else {
+        xrefEntry = parser.getObj();
+      }
+      if (!isStream(xrefEntry)) {
+        this.cache[num] = xrefEntry;
+      }
+      return xrefEntry;
+    },
+
+    fetchCompressed: function XRef_fetchCompressed(xrefEntry,
+                                                   suppressEncryption) {
+      var tableOffset = xrefEntry.offset;
+      var stream = this.fetch(new Ref(tableOffset, 0));
+      if (!isStream(stream)) {
+        error('bad ObjStm stream');
+      }
+      var first = stream.dict.get('First');
+      var n = stream.dict.get('N');
+      if (!isInt(first) || !isInt(n)) {
+        error('invalid first and n parameters for ObjStm stream');
+      }
+      var parser = new Parser(new Lexer(stream), false, this);
+      parser.allowStreams = true;
+      var i, entries = [], num, nums = [];
+      // read the object numbers to populate cache
+      for (i = 0; i < n; ++i) {
+        num = parser.getObj();
+        if (!isInt(num)) {
+          error('invalid object number in the ObjStm stream: ' + num);
+        }
+        nums.push(num);
+        var offset = parser.getObj();
+        if (!isInt(offset)) {
+          error('invalid object offset in the ObjStm stream: ' + offset);
+        }
+      }
+      // read stream objects for cache
+      for (i = 0; i < n; ++i) {
+        entries.push(parser.getObj());
+        num = nums[i];
+        var entry = this.entries[num];
+        if (entry && entry.offset === tableOffset && entry.gen === i) {
+          this.cache[num] = entries[i];
+        }
+      }
+      xrefEntry = entries[xrefEntry.gen];
+      if (xrefEntry === undefined) {
+        error('bad XRef entry for compressed object');
+      }
+      return xrefEntry;
+    },
+
+    fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
+      if (!isRef(obj)) {
+        return Promise.resolve(obj);
+      }
+      return this.fetchAsync(obj);
+    },
+
+    fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
+      var streamManager = this.stream.manager;
+      var xref = this;
+      return new Promise(function tryFetch(resolve, reject) {
+        try {
+          resolve(xref.fetch(ref, suppressEncryption));
+        } catch (e) {
+          if (e instanceof MissingDataException) {
+            streamManager.requestRange(e.begin, e.end).then(function () {
+              tryFetch(resolve, reject);
+            }, reject);
+            return;
+          }
+          reject(e);
+        }
+      });
+    },
+
+    getCatalogObj: function XRef_getCatalogObj() {
+      return this.root;
+    }
+  };
+
+  return XRef;
+})();
+
+/**
+ * A NameTree/NumberTree is like a Dict but has some advantageous properties,
+ * see the specification (7.9.6 and 7.9.7) for additional details.
+ * TODO: implement all the Dict functions and make this more efficient.
+ */
+var NameOrNumberTree = (function NameOrNumberTreeClosure() {
+  function NameOrNumberTree(root, xref) {
+    throw new Error('Cannot initialize NameOrNumberTree.');
+  }
+
+  NameOrNumberTree.prototype = {
+    getAll: function NameOrNumberTree_getAll() {
+      var dict = Object.create(null);
+      if (!this.root) {
+        return dict;
+      }
+      var xref = this.xref;
+      // Reading Name/Number tree.
+      var processed = new RefSet();
+      processed.put(this.root);
+      var queue = [this.root];
+      while (queue.length > 0) {
+        var i, n;
+        var obj = xref.fetchIfRef(queue.shift());
+        if (!isDict(obj)) {
+          continue;
+        }
+        if (obj.has('Kids')) {
+          var kids = obj.get('Kids');
+          for (i = 0, n = kids.length; i < n; i++) {
+            var kid = kids[i];
+            assert(!processed.has(kid),
+                   'Duplicate entry in "' + this._type + '" tree.');
+            queue.push(kid);
+            processed.put(kid);
+          }
+          continue;
+        }
+        var entries = obj.get(this._type);
+        if (isArray(entries)) {
+          for (i = 0, n = entries.length; i < n; i += 2) {
+            dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
+          }
+        }
+      }
+      return dict;
+    },
+
+    get: function NameOrNumberTree_get(key) {
+      if (!this.root) {
+        return null;
+      }
+
+      var xref = this.xref;
+      var kidsOrEntries = xref.fetchIfRef(this.root);
+      var loopCount = 0;
+      var MAX_LEVELS = 10;
+      var l, r, m;
+
+      // Perform a binary search to quickly find the entry that
+      // contains the key we are looking for.
+      while (kidsOrEntries.has('Kids')) {
+        if (++loopCount > MAX_LEVELS) {
+          warn('Search depth limit reached for "' + this._type + '" tree.');
+          return null;
+        }
+
+        var kids = kidsOrEntries.get('Kids');
+        if (!isArray(kids)) {
+          return null;
+        }
+
+        l = 0;
+        r = kids.length - 1;
+        while (l <= r) {
+          m = (l + r) >> 1;
+          var kid = xref.fetchIfRef(kids[m]);
+          var limits = kid.get('Limits');
+
+          if (key < xref.fetchIfRef(limits[0])) {
+            r = m - 1;
+          } else if (key > xref.fetchIfRef(limits[1])) {
+            l = m + 1;
+          } else {
+            kidsOrEntries = xref.fetchIfRef(kids[m]);
+            break;
+          }
+        }
+        if (l > r) {
+          return null;
+        }
+      }
+
+      // If we get here, then we have found the right entry. Now go through the
+      // entries in the dictionary until we find the key we're looking for.
+      var entries = kidsOrEntries.get(this._type);
+      if (isArray(entries)) {
+        // Perform a binary search to reduce the lookup time.
+        l = 0;
+        r = entries.length - 2;
+        while (l <= r) {
+          // Check only even indices (0, 2, 4, ...) because the
+          // odd indices contain the actual data.
+          m = (l + r) & ~1;
+          var currentKey = xref.fetchIfRef(entries[m]);
+          if (key < currentKey) {
+            r = m - 2;
+          } else if (key > currentKey) {
+            l = m + 2;
+          } else {
+            return xref.fetchIfRef(entries[m + 1]);
+          }
+        }
+      }
+      return null;
+    }
+  };
+  return NameOrNumberTree;
+})();
+
+var NameTree = (function NameTreeClosure() {
+  function NameTree(root, xref) {
+    this.root = root;
+    this.xref = xref;
+    this._type = 'Names';
+  }
+
+  Util.inherit(NameTree, NameOrNumberTree, {});
+
+  return NameTree;
+})();
+
+var NumberTree = (function NumberTreeClosure() {
+  function NumberTree(root, xref) {
+    this.root = root;
+    this.xref = xref;
+    this._type = 'Nums';
+  }
+
+  Util.inherit(NumberTree, NameOrNumberTree, {});
+
+  return NumberTree;
+})();
+
+/**
+ * "A PDF file can refer to the contents of another file by using a File
+ * Specification (PDF 1.1)", see the spec (7.11) for more details.
+ * NOTE: Only embedded files are supported (as part of the attachments support)
+ * TODO: support the 'URL' file system (with caching if !/V), portable
+ * collections attributes and related files (/RF)
+ */
+var FileSpec = (function FileSpecClosure() {
+  function FileSpec(root, xref) {
+    if (!root || !isDict(root)) {
+      return;
+    }
+    this.xref = xref;
+    this.root = root;
+    if (root.has('FS')) {
+      this.fs = root.get('FS');
+    }
+    this.description = root.has('Desc') ?
+                         stringToPDFString(root.get('Desc')) :
+                         '';
+    if (root.has('RF')) {
+      warn('Related file specifications are not supported');
+    }
+    this.contentAvailable = true;
+    if (!root.has('EF')) {
+      this.contentAvailable = false;
+      warn('Non-embedded file specifications are not supported');
+    }
+  }
+
+  function pickPlatformItem(dict) {
+    // Look for the filename in this order:
+    // UF, F, Unix, Mac, DOS
+    if (dict.has('UF')) {
+      return dict.get('UF');
+    } else if (dict.has('F')) {
+      return dict.get('F');
+    } else if (dict.has('Unix')) {
+      return dict.get('Unix');
+    } else if (dict.has('Mac')) {
+      return dict.get('Mac');
+    } else if (dict.has('DOS')) {
+      return dict.get('DOS');
+    } else {
+      return null;
+    }
+  }
+
+  FileSpec.prototype = {
+    get filename() {
+      if (!this._filename && this.root) {
+        var filename = pickPlatformItem(this.root) || 'unnamed';
+        this._filename = stringToPDFString(filename).
+          replace(/\\\\/g, '\\').
+          replace(/\\\//g, '/').
+          replace(/\\/g, '/');
+      }
+      return this._filename;
+    },
+    get content() {
+      if (!this.contentAvailable) {
+        return null;
+      }
+      if (!this.contentRef && this.root) {
+        this.contentRef = pickPlatformItem(this.root.get('EF'));
+      }
+      var content = null;
+      if (this.contentRef) {
+        var xref = this.xref;
+        var fileObj = xref.fetchIfRef(this.contentRef);
+        if (fileObj && isStream(fileObj)) {
+          content = fileObj.getBytes();
+        } else {
+          warn('Embedded file specification points to non-existing/invalid ' +
+            'content');
+        }
+      } else {
+        warn('Embedded file specification does not have a content');
+      }
+      return content;
+    },
+    get serializable() {
+      return {
+        filename: this.filename,
+        content: this.content
+      };
+    }
+  };
+  return FileSpec;
+})();
+
+/**
+ * A helper for loading missing data in object graphs. It traverses the graph
+ * depth first and queues up any objects that have missing data. Once it has
+ * has traversed as many objects that are available it attempts to bundle the
+ * missing data requests and then resume from the nodes that weren't ready.
+ *
+ * NOTE: It provides protection from circular references by keeping track of
+ * of loaded references. However, you must be careful not to load any graphs
+ * that have references to the catalog or other pages since that will cause the
+ * entire PDF document object graph to be traversed.
+ */
+var ObjectLoader = (function() {
+  function mayHaveChildren(value) {
+    return isRef(value) || isDict(value) || isArray(value) || isStream(value);
+  }
+
+  function addChildren(node, nodesToVisit) {
+    var value;
+    if (isDict(node) || isStream(node)) {
+      var map;
+      if (isDict(node)) {
+        map = node.map;
+      } else {
+        map = node.dict.map;
+      }
+      for (var key in map) {
+        value = map[key];
+        if (mayHaveChildren(value)) {
+          nodesToVisit.push(value);
+        }
+      }
+    } else if (isArray(node)) {
+      for (var i = 0, ii = node.length; i < ii; i++) {
+        value = node[i];
+        if (mayHaveChildren(value)) {
+          nodesToVisit.push(value);
+        }
+      }
+    }
+  }
+
+  function ObjectLoader(obj, keys, xref) {
+    this.obj = obj;
+    this.keys = keys;
+    this.xref = xref;
+    this.refSet = null;
+    this.capability = null;
+  }
+
+  ObjectLoader.prototype = {
+    load: function ObjectLoader_load() {
+      var keys = this.keys;
+      this.capability = createPromiseCapability();
+      // Don't walk the graph if all the data is already loaded.
+      if (!(this.xref.stream instanceof ChunkedStream) ||
+          this.xref.stream.getMissingChunks().length === 0) {
+        this.capability.resolve();
+        return this.capability.promise;
+      }
+
+      this.refSet = new RefSet();
+      // Setup the initial nodes to visit.
+      var nodesToVisit = [];
+      for (var i = 0; i < keys.length; i++) {
+        nodesToVisit.push(this.obj[keys[i]]);
+      }
+
+      this._walk(nodesToVisit);
+      return this.capability.promise;
+    },
+
+    _walk: function ObjectLoader_walk(nodesToVisit) {
+      var nodesToRevisit = [];
+      var pendingRequests = [];
+      // DFS walk of the object graph.
+      while (nodesToVisit.length) {
+        var currentNode = nodesToVisit.pop();
+
+        // Only references or chunked streams can cause missing data exceptions.
+        if (isRef(currentNode)) {
+          // Skip nodes that have already been visited.
+          if (this.refSet.has(currentNode)) {
+            continue;
+          }
+          try {
+            var ref = currentNode;
+            this.refSet.put(ref);
+            currentNode = this.xref.fetch(currentNode);
+          } catch (e) {
+            if (!(e instanceof MissingDataException)) {
+              throw e;
+            }
+            nodesToRevisit.push(currentNode);
+            pendingRequests.push({ begin: e.begin, end: e.end });
+          }
+        }
+        if (currentNode && currentNode.getBaseStreams) {
+          var baseStreams = currentNode.getBaseStreams();
+          var foundMissingData = false;
+          for (var i = 0; i < baseStreams.length; i++) {
+            var stream = baseStreams[i];
+            if (stream.getMissingChunks && stream.getMissingChunks().length) {
+              foundMissingData = true;
+              pendingRequests.push({
+                begin: stream.start,
+                end: stream.end
+              });
+            }
+          }
+          if (foundMissingData) {
+            nodesToRevisit.push(currentNode);
+          }
+        }
+
+        addChildren(currentNode, nodesToVisit);
+      }
+
+      if (pendingRequests.length) {
+        this.xref.stream.manager.requestRanges(pendingRequests).then(
+            function pendingRequestCallback() {
+          nodesToVisit = nodesToRevisit;
+          for (var i = 0; i < nodesToRevisit.length; i++) {
+            var node = nodesToRevisit[i];
+            // Remove any reference nodes from the currrent refset so they
+            // aren't skipped when we revist them.
+            if (isRef(node)) {
+              this.refSet.remove(node);
+            }
+          }
+          this._walk(nodesToVisit);
+        }.bind(this), this.capability.reject);
+        return;
+      }
+      // Everything is loaded.
+      this.refSet = null;
+      this.capability.resolve();
+    }
+  };
+
+  return ObjectLoader;
+})();
+
+exports.Catalog = Catalog;
+exports.ObjectLoader = ObjectLoader;
+exports.XRef = XRef;
+}));
+
+
+(function (root, factory) {
+  {
     factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
       root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
       root.pdfjsCoreColorSpace);
   }
 }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
                   coreColorSpace) {
 
 var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
@@ -36814,19 +36765,30 @@ var PartialEvaluator = (function Partial
               // Ignore operators where the corresponding handlers are known to
               // be no-op in CanvasGraphics (display/canvas.js). This prevents
               // serialization errors and is also a bit more efficient.
               // We could also try to serialize all objects in a general way,
               // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
               // but doing so is meaningless without knowing the semantics.
               continue;
             default:
-              // Note: Let's hope that the ignored operator does not have any
-              // non-serializable arguments, otherwise postMessage will throw
+              // Note: Ignore the operator if it has `Dict` arguments, since
+              // those are non-serializable, otherwise postMessage will throw
               // "An object could not be cloned.".
+              if (args !== null) {
+                for (i = 0, ii = args.length; i < ii; i++) {
+                  if (args[i] instanceof Dict) {
+                    break;
+                  }
+                }
+                if (i < ii) {
+                  warn('getOperatorList - ignoring operator: ' + fn);
+                  continue;
+                }
+              }
           }
           operatorList.addOp(fn, args);
         }
         if (stop) {
           deferred.then(function () {
             next(resolve, reject);
           }, reject);
           return;
@@ -38364,17 +38326,17 @@ var EvaluatorPreprocessor = (function Ev
           if (isEOF(obj)) {
             return false; // no more commands
           }
           // argument
           if (obj !== null) {
             if (!args) {
               args = [];
             }
-            args.push((obj instanceof Dict ? obj.getAll() : obj));
+            args.push(obj);
             assert(args.length <= 33, 'Too many arguments');
           }
         }
       }
     },
 
     preprocessCommand:
         function EvaluatorPreprocessor_preprocessCommand(fn, args) {
@@ -39395,17 +39357,16 @@ var WidgetAnnotation = (function WidgetA
   return WidgetAnnotation;
 })();
 
 var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
   function TextWidgetAnnotation(params) {
     WidgetAnnotation.call(this, params);
 
     this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
-    this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
   }
 
   Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
     getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
                                                                    task) {
       if (this.appearance) {
         return Annotation.prototype.getOperatorList.call(this, evaluator, task);
       }
@@ -39433,17 +39394,16 @@ var TextWidgetAnnotation = (function Tex
 
 var TextAnnotation = (function TextAnnotationClosure() {
   var DEFAULT_ICON_SIZE = 22; // px
 
   function TextAnnotation(parameters) {
     Annotation.call(this, parameters);
 
     this.data.annotationType = AnnotationType.TEXT;
-    this.data.hasHtml = true;
 
     var dict = parameters.dict;
     if (this.data.hasAppearance) {
       this.data.name = 'NoIcon';
     } else {
       this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
       this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
       this.data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
@@ -39455,33 +39415,31 @@ var TextAnnotation = (function TextAnnot
     }
 
     this.data.hasPopup = dict.has('Popup');
     if (!this.data.hasPopup) {
       // There is no associated Popup annotation, so the Text annotation
       // must create its own popup.
       this.data.title = stringToPDFString(dict.get('T') || '');
       this.data.contents = stringToPDFString(dict.get('Contents') || '');
-      this.data.hasHtml = (this.data.title || this.data.contents);
     }
   }
 
   Util.inherit(TextAnnotation, Annotation, {});
 
   return TextAnnotation;
 })();
 
 var LinkAnnotation = (function LinkAnnotationClosure() {
   function LinkAnnotation(params) {
     Annotation.call(this, params);
 
     var dict = params.dict;
     var data = this.data;
     data.annotationType = AnnotationType.LINK;
-    data.hasHtml = true;
 
     var action = dict.get('A');
     if (action && isDict(action)) {
       var linkType = action.get('S').name;
       if (linkType === 'URI') {
         var url = action.get('URI');
         if (isName(url)) {
           // Some bad PDFs do not put parentheses around relative URLs.
@@ -39564,79 +39522,73 @@ var PopupAnnotation = (function PopupAnn
 
     if (!parentItem.has('C')) {
       // Fall back to the default background color.
       this.data.color = null;
     } else {
       this.setColor(parentItem.get('C'));
       this.data.color = this.color;
     }
-
-    this.data.hasHtml = (this.data.title || this.data.contents);
   }
 
   Util.inherit(PopupAnnotation, Annotation, {});
 
   return PopupAnnotation;
 })();
 
 var HighlightAnnotation = (function HighlightAnnotationClosure() {
   function HighlightAnnotation(parameters) {
     Annotation.call(this, parameters);
 
     this.data.annotationType = AnnotationType.HIGHLIGHT;
-    this.data.hasHtml = true;
 
     // PDF viewers completely ignore any border styles.
     this.data.borderStyle.setWidth(0);
   }
 
   Util.inherit(HighlightAnnotation, Annotation, {});
 
   return HighlightAnnotation;
 })();
 
 var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
   function UnderlineAnnotation(parameters) {
     Annotation.call(this, parameters);
 
     this.data.annotationType = AnnotationType.UNDERLINE;
-    this.data.hasHtml = true;
 
     // PDF viewers completely ignore any border styles.
     this.data.borderStyle.setWidth(0);
   }
 
   Util.inherit(UnderlineAnnotation, Annotation, {});
 
   return UnderlineAnnotation;
 })();
 
 var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
   function SquigglyAnnotation(parameters) {
     Annotation.call(this, parameters);
 
     this.data.annotationType = AnnotationType.SQUIGGLY;
-    this.data.hasHtml = true;
 
     // PDF viewers completely ignore any border styles.
     this.data.borderStyle.setWidth(0);
   }
 
   Util.inherit(SquigglyAnnotation, Annotation, {});
 
   return SquigglyAnnotation;
 })();
 
 var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
   function StrikeOutAnnotation(parameters) {
     Annotation.call(this, parameters);
 
     this.data.annotationType = AnnotationType.STRIKEOUT;
-    this.data.hasHtml = true;
 
     // PDF viewers completely ignore any border styles.
     this.data.borderStyle.setWidth(0);
   }
 
   Util.inherit(StrikeOutAnnotation, Annotation, {});
 
   return StrikeOutAnnotation;
--- a/browser/extensions/pdfjs/content/web/viewer.html
+++ b/browser/extensions/pdfjs/content/web/viewer.html
@@ -22,22 +22,22 @@ See https://github.com/adobe-type-tools/
 -->
 <html dir="ltr" mozdisallowselectionprint moznomarginboxes>
   <head>
     <meta charset="utf-8">
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
     <title>PDF.js viewer</title>
 
 <!-- This snippet is used in the Firefox extension (included from viewer.html) -->
-<base href="resource://pdf.js/web/" />
+<base href="resource://pdf.js/web/">
 <script src="l10n.js"></script>
 <script src="../build/pdf.js"></script>
 
 
-    <link rel="stylesheet" href="viewer.css"/>
+    <link rel="stylesheet" href="viewer.css">
 
 
 
 
 
 
     <script src="debugger.js"></script>
     <script src="viewer.js"></script>
@@ -274,17 +274,17 @@ See https://github.com/adobe-type-tools/
       <div id="overlayContainer" class="hidden">
         <div id="passwordOverlay" class="container hidden">
           <div class="dialog">
             <div class="row">
               <p id="passwordText" data-l10n-id="password_label">Enter the password to open this PDF file:</p>
             </div>
             <div class="row">
               <!-- The type="password" attribute is set via script, to prevent warnings in Firefox for all http:// documents. -->
-              <input id="password" class="toolbarField" />
+              <input id="password" class="toolbarField">
             </div>
             <div class="buttonRow">
               <button id="passwordCancel" class="overlayButton"><span data-l10n-id="password_cancel">Cancel</span></button>
               <button id="passwordSubmit" class="overlayButton"><span data-l10n-id="password_ok">OK</span></button>
             </div>
           </div>
         </div>
         <div id="documentPropertiesOverlay" class="container hidden">