Guest User

api.js

a guest
Jan 2nd, 2013
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  'use strict';
  2.  
  3. PDFJS.getDocument = function getDocument(source) {
  4.   var workerInitializedPromise, workerReadyPromise, transport;
  5.  
  6.   if (typeof source === 'string') {
  7.     source = { url: source };
  8.   } else if (isArrayBuffer(source)) {
  9.     source = { data: source };
  10.   } else if (typeof source !== 'object') {
  11.     error('Invalid parameter in getDocument, need either Uint8Array, ' +
  12.           'string or a parameter object');
  13.   }
  14.  
  15.   if (!source.url && !source.data)
  16.     error('Invalid parameter array, need either .data or .url');
  17.  
  18.   // copy/use all keys as is except 'url' -- full path is required
  19.   var params = {};
  20.   for (var key in source) {
  21.     if (key === 'url' && typeof window !== 'undefined') {
  22.       params[key] = combineUrl(window.location.href, source[key]);
  23.       continue;
  24.     }
  25.     params[key] = source[key];
  26.   }
  27.  
  28.   workerInitializedPromise = new PDFJS.Promise();
  29.   workerReadyPromise = new PDFJS.Promise();
  30.   transport = new WorkerTransport(workerInitializedPromise, workerReadyPromise);
  31.   workerInitializedPromise.then(function transportInitialized() {
  32.     transport.fetchDocument(params);
  33.   });
  34.   return workerReadyPromise;
  35. };
  36.  
  37. /**
  38.  * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  39.  * properties that can be read synchronously.
  40.  */
  41. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  42.   function PDFDocumentProxy(pdfInfo, transport) {
  43.     this.pdfInfo = pdfInfo;
  44.     this.transport = transport;
  45.   }
  46.   PDFDocumentProxy.prototype = {
  47.     /**
  48.      * @return {number} Total number of pages the PDF contains.
  49.      */
  50.     get numPages() {
  51.       return this.pdfInfo.numPages;
  52.     },
  53.     /**
  54.      * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  55.      * unique.
  56.      */
  57.     get fingerprint() {
  58.       return this.pdfInfo.fingerprint;
  59.     },
  60.     /**
  61.      * @return {boolean} true if embedded document fonts are in use. Will be
  62.      * set during rendering of the pages.
  63.      */
  64.     get embeddedFontsUsed() {
  65.       return this.transport.embeddedFontsUsed;
  66.     },
  67.     /**
  68.      * @param {number} The page number to get. The first page is 1.
  69.      * @return {Promise} A promise that is resolved with a {PDFPageProxy}
  70.      * object.
  71.      */
  72.     getPage: function PDFDocumentProxy_getPage(number) {
  73.       return this.transport.getPage(number);
  74.     },
  75.     /**
  76.      * @return {Promise} A promise that is resolved with a lookup table for
  77.      * mapping named destinations to reference numbers.
  78.      */
  79.     getDestinations: function PDFDocumentProxy_getDestinations() {
  80.       var promise = new PDFJS.Promise();
  81.       var destinations = this.pdfInfo.destinations;
  82.       promise.resolve(destinations);
  83.       return promise;
  84.     },
  85.     /**
  86.      * @return {Promise} A promise that is resolved with an {array} that is a
  87.      * tree outline (if it has one) of the PDF. The tree is in the format of:
  88.      * [
  89.      *  {
  90.      *   title: string,
  91.      *   bold: boolean,
  92.      *   italic: boolean,
  93.      *   color: rgb array,
  94.      *   dest: dest obj,
  95.      *   items: array of more items like this
  96.      *  },
  97.      *  ...
  98.      * ].
  99.      */
  100.     getOutline: function PDFDocumentProxy_getOutline() {
  101.       var promise = new PDFJS.Promise();
  102.       var outline = this.pdfInfo.outline;
  103.       promise.resolve(outline);
  104.       return promise;
  105.     },
  106.     /**
  107.      * @return {Promise} A promise that is resolved with an {object} that has
  108.      * info and metadata properties.  Info is an {object} filled with anything
  109.      * available in the information dictionary and similarly metadata is a
  110.      * {Metadata} object with information from the metadata section of the PDF.
  111.      */
  112.     getMetadata: function PDFDocumentProxy_getMetadata() {
  113.       var promise = new PDFJS.Promise();
  114.       var info = this.pdfInfo.info;
  115.       var metadata = this.pdfInfo.metadata;
  116.       promise.resolve({
  117.         info: info,
  118.         metadata: metadata ? new PDFJS.Metadata(metadata) : null
  119.       });
  120.       return promise;
  121.     },
  122.     isEncrypted: function PDFDocumentProxy_isEncrypted() {
  123.       var promise = new PDFJS.Promise();
  124.       promise.resolve(this.pdfInfo.encrypted);
  125.       return promise;
  126.     },
  127.     /**
  128.      * @return {Promise} A promise that is resolved with a TypedArray that has
  129.      * the raw data from the PDF.
  130.      */
  131.     getData: function PDFDocumentProxy_getData() {
  132.       var promise = new PDFJS.Promise();
  133.       this.transport.getData(promise);
  134.       return promise;
  135.     },
  136.     destroy: function PDFDocumentProxy_destroy() {
  137.       this.transport.destroy();
  138.     }
  139.   };
  140.   return PDFDocumentProxy;
  141. })();
  142.  
  143. var PDFPageProxy = (function PDFPageProxyClosure() {
  144.   function PDFPageProxy(pageInfo, transport) {
  145.     this.pageInfo = pageInfo;
  146.     this.transport = transport;
  147.     this.stats = new StatTimer();
  148.     this.stats.enabled = !!globalScope.PDFJS.enableStats;
  149.     this.commonObjs = transport.commonObjs;
  150.     this.objs = new PDFObjects();
  151.     this.renderInProgress = false;
  152.     this.cleanupAfterRender = false;
  153.   }
  154.   PDFPageProxy.prototype = {
  155.     /**
  156.      * @return {number} Page number of the page. First page is 1.
  157.      */
  158.     get pageNumber() {
  159.       return this.pageInfo.pageIndex + 1;
  160.     },
  161.     /**
  162.      * @return {number} The number of degrees the page is rotated clockwise.
  163.      */
  164.     get rotate() {
  165.       return this.pageInfo.rotate;
  166.     },
  167.     /**
  168.      * @return {object} The reference that points to this page. It has 'num' and
  169.      * 'gen' properties.
  170.      */
  171.     get ref() {
  172.       return this.pageInfo.ref;
  173.     },
  174.     /**
  175.      * @return {array} An array of the visible portion of the PDF page in the
  176.      * user space units - [x1, y1, x2, y2].
  177.      */
  178.     get view() {
  179.       return this.pageInfo.view;
  180.     },
  181.     /**
  182.      * @param {number} scale The desired scale of the viewport.
  183.      * @param {number} rotate Degrees to rotate the viewport. If omitted this
  184.      * defaults to the page rotation.
  185.      * @return {PageViewport} Contains 'width' and 'height' properties along
  186.      * with transforms required for rendering.
  187.      */
  188.     getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  189.       if (arguments.length < 2)
  190.         rotate = this.rotate;
  191.       return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  192.     },
  193.     /**
  194.      * @return {Promise} A promise that is resolved with an {array} of the
  195.      * annotation objects.
  196.      */
  197.     getAnnotations: function PDFPageProxy_getAnnotations() {
  198.       if (this.annotationsPromise)
  199.         return this.annotationsPromise;
  200.  
  201.       var promise = new PDFJS.Promise();
  202.       this.annotationsPromise = promise;
  203.       this.transport.getAnnotations(this.pageInfo.pageIndex);
  204.       return promise;
  205.     },
  206.     /**
  207.      * Begins the process of rendering a page to the desired context.
  208.      * @param {object} params A parameter object that supports:
  209.      * {
  210.      *   canvasContext(required): A 2D context of a DOM Canvas object.,
  211.      *   textLayer(optional): An object that has beginLayout, endLayout, and
  212.      *                        appendText functions.,
  213.      *   continueCallback(optional): A function that will be called each time
  214.      *                               the rendering is paused.  To continue
  215.      *                               rendering call the function that is the
  216.      *                               first argument to the callback.
  217.      * }.
  218.      * @return {Promise} A promise that is resolved when the page finishes
  219.      * rendering.
  220.      */
  221.     render: function PDFPageProxy_render(params) {
  222.       this.renderInProgress = true;
  223.  
  224.       var promise = new Promise();
  225.       var stats = this.stats;
  226.       stats.time('Overall');
  227.       // If there is no displayReadyPromise yet, then the operatorList was never
  228.       // requested before. Make the request and create the promise.
  229.       if (!this.displayReadyPromise) {
  230.         this.displayReadyPromise = new Promise();
  231.         this.destroyed = false;
  232.  
  233.         this.stats.time('Page Request');
  234.         this.transport.messageHandler.send('RenderPageRequest', {
  235.           pageIndex: this.pageNumber - 1
  236.         });
  237.       }
  238.  
  239.       var self = this;
  240.       function complete(error) {
  241.         self.renderInProgress = false;
  242.         if (self.destroyed || self.cleanupAfterRender) {
  243.           delete self.displayReadyPromise;
  244.           delete self.operatorList;
  245.           self.objs.clear();
  246.         }
  247.  
  248.         if (error)
  249.           promise.reject(error);
  250.         else
  251.           promise.resolve();
  252.       };
  253.       var continueCallback = params.continueCallback;
  254.  
  255.       // Once the operatorList and fonts are loaded, do the actual rendering.
  256.       this.displayReadyPromise.then(
  257.         function pageDisplayReadyPromise() {
  258.           if (self.destroyed) {
  259.             complete();
  260.             return;
  261.           }
  262.  
  263.           var gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  264.             this.objs, params.textLayer);
  265.           try {
  266.             this.display(gfx, params.viewport, complete, continueCallback);
  267.           } catch (e) {
  268.             complete(e);
  269.           }
  270.         }.bind(this),
  271.         function pageDisplayReadPromiseError(reason) {
  272.           complete(reason);
  273.         }
  274.       );
  275.  
  276.       return promise;
  277.     },
  278.     /**
  279.      * For internal use only.
  280.      */
  281.     startRenderingFromOperatorList:
  282.       function PDFPageProxy_startRenderingFromOperatorList(operatorList,
  283.                                                            fonts) {
  284.       var self = this;
  285.       this.operatorList = operatorList;
  286.  
  287.       var displayContinuation = function pageDisplayContinuation() {
  288.         // Always defer call to display() to work around bug in
  289.         // Firefox error reporting from XHR callbacks.
  290.         setTimeout(function pageSetTimeout() {
  291.           self.displayReadyPromise.resolve();
  292.         });
  293.       };
  294.  
  295.       this.ensureFonts(fonts,
  296.         function pageStartRenderingFromOperatorListEnsureFonts() {
  297.           displayContinuation();
  298.         }
  299.       );
  300.     },
  301.     /**
  302.      * For internal use only.
  303.      */
  304.     ensureFonts: function PDFPageProxy_ensureFonts(fonts, callback) {
  305.       this.stats.time('Font Loading');
  306.       // Convert the font names to the corresponding font obj.
  307.       var fontObjs = [];
  308.       for (var i = 0, ii = fonts.length; i < ii; i++) {
  309.         var obj = this.commonObjs.getData(fonts[i]);
  310.         if (obj.error) {
  311.           warn('Error during font loading: ' + obj.error);
  312.           continue;
  313.         }
  314.         if (!obj.coded) {
  315.           this.transport.embeddedFontsUsed = true;
  316.         }
  317.         fontObjs.push(obj);
  318.       }
  319.  
  320.       // Load all the fonts
  321.       FontLoader.bind(
  322.         fontObjs,
  323.         function pageEnsureFontsFontObjs(fontObjs) {
  324.           this.stats.timeEnd('Font Loading');
  325.  
  326.           callback.call(this);
  327.         }.bind(this)
  328.       );
  329.     },
  330.     /**
  331.      * For internal use only.
  332.      */
  333.     display: function PDFPageProxy_display(gfx, viewport, callback,
  334.                                            continueCallback) {
  335.       var stats = this.stats;
  336.       stats.time('Rendering');
  337.  
  338.       gfx.beginDrawing(viewport);
  339.  
  340.       var startIdx = 0;
  341.       var length = this.operatorList.fnArray.length;
  342.       var operatorList = this.operatorList;
  343.       var stepper = null;
  344.       if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  345.           globalScope['StepperManager'].enabled) {
  346.         stepper = globalScope['StepperManager'].create(this.pageNumber - 1);
  347.         stepper.init(operatorList);
  348.         stepper.nextBreakPoint = stepper.getNextBreakPoint();
  349.       }
  350.  
  351.       var continueWrapper;
  352.       if (continueCallback)
  353.         continueWrapper = function() { continueCallback(next); }
  354.       else
  355.         continueWrapper = next;
  356.  
  357.       var self = this;
  358.       function next() {
  359.         startIdx = gfx.executeOperatorList(operatorList, startIdx,
  360.                                            continueWrapper, stepper);
  361.         if (startIdx == length) {
  362.           gfx.endDrawing();
  363.           stats.timeEnd('Rendering');
  364.           stats.timeEnd('Overall');
  365.           if (callback) callback();
  366.         }
  367.       }
  368.       continueWrapper();
  369.     },
  370.     /**
  371.      * @return {Promise} That is resolved with the a {string} that is the text
  372.      * content from the page.
  373.      */
  374.     getTextContent: function PDFPageProxy_getTextContent() {
  375.       var promise = new PDFJS.Promise();
  376.       this.transport.messageHandler.send('GetTextContent', {
  377.           pageIndex: this.pageNumber - 1
  378.         },
  379.         function textContentCallback(textContent) {
  380.           promise.resolve(textContent);
  381.         }
  382.       );
  383.       return promise;
  384.     },
  385.     /**
  386.      * Stub for future feature.
  387.      */
  388.     getOperationList: function PDFPageProxy_getOperationList() {
  389.       var promise = new PDFJS.Promise();
  390.       var operationList = { // not implemented
  391.         dependencyFontsID: null,
  392.         operatorList: null
  393.       };
  394.       promise.resolve(operationList);
  395.       return promise;
  396.     },
  397.     /**
  398.      * Destroys resources allocated by the page.
  399.      */
  400.     destroy: function PDFPageProxy_destroy() {
  401.       this.destroyed = true;
  402.  
  403.       if (!this.renderInProgress) {
  404.         delete this.operatorList;
  405.         delete this.displayReadyPromise;
  406.         this.objs.clear();
  407.       }
  408.     }
  409.   };
  410.   return PDFPageProxy;
  411. })();
  412. /**
  413.  * For internal use only.
  414.  */
  415. var WorkerTransport = (function WorkerTransportClosure() {
  416.     function WorkerTransport(workerInitializedPromise, workerReadyPromise) {
  417.     this.workerReadyPromise = workerReadyPromise;
  418.     this.commonObjs = new PDFObjects();
  419.  
  420.     this.pageCache = [];
  421.     this.pagePromises = [];
  422.     this.embeddedFontsUsed = false;
  423.  
  424.     // If worker support isn't disabled explicit and the browser has worker
  425.     // support, create a new web worker and test if it/the browser fullfills
  426.     // all requirements to run parts of pdf.js in a web worker.
  427.     // Right now, the requirement is, that an Uint8Array is still an Uint8Array
  428.       // as it arrives on the worker. Chrome added this with version 15.
  429.     if (!globalScope.PDFJS.disableWorker && typeof Worker !== 'undefined') {
  430.         var workerSrc = '/pdf.js/worker_loader.js';
  431.       if (typeof workerSrc === 'undefined') {
  432.         error('No PDFJS.workerSrc specified');
  433.       }
  434.  
  435.       try {
  436.         // Some versions of FF can't create a worker on localhost, see:
  437.         // https://bugzilla.mozilla.org/show_bug.cgi?id=683280
  438.           var worker = new Worker('/pdf.js/worker_loader.js');
  439.         var messageHandler = new MessageHandler('main', worker);
  440.         this.messageHandler = messageHandler;
  441.  
  442.         messageHandler.on('test', function transportTest(supportTypedArray) {
  443.           if (supportTypedArray) {
  444.             this.worker = worker;
  445.             this.setupMessageHandler(messageHandler);
  446.           } else {
  447.             globalScope.PDFJS.disableWorker = true;
  448.             this.setupFakeWorker();
  449.           }
  450.           workerInitializedPromise.resolve();
  451.         }.bind(this));
  452.  
  453.         var testObj = new Uint8Array(1);
  454.         // Some versions of Opera throw a DATA_CLONE_ERR on
  455.         // serializing the typed array.
  456.         messageHandler.send('test', testObj);
  457.         return;
  458.       } catch (e) {
  459.         info('The worker has been disabled.');
  460.       }
  461.     }
  462.     // Either workers are disabled, not supported or have thrown an exception.
  463.     // Thus, we fallback to a faked worker.
  464.     globalScope.PDFJS.disableWorker = true;
  465.     this.setupFakeWorker();
  466.     workerInitializedPromise.resolve();
  467.   }
  468.   WorkerTransport.prototype = {
  469.     destroy: function WorkerTransport_destroy() {
  470.       if (this.worker)
  471.         this.worker.terminate();
  472.  
  473.       this.pageCache = [];
  474.       this.pagePromises = [];
  475.     },
  476.     setupFakeWorker: function WorkerTransport_setupFakeWorker() {
  477.       warn('Setting up fake worker.');
  478.       // If we don't use a worker, just post/sendMessage to the main thread.
  479.       var fakeWorker = {
  480.         postMessage: function WorkerTransport_postMessage(obj) {
  481.           fakeWorker.onmessage({data: obj});
  482.         },
  483.         terminate: function WorkerTransport_terminate() {}
  484.       };
  485.  
  486.       var messageHandler = new MessageHandler('main', fakeWorker);
  487.       this.setupMessageHandler(messageHandler);
  488.  
  489.       // If the main thread is our worker, setup the handling for the messages
  490.       // the main thread sends to it self.
  491.       WorkerMessageHandler.setup(messageHandler);
  492.     },
  493.  
  494.     setupMessageHandler:
  495.       function WorkerTransport_setupMessageHandler(messageHandler) {
  496.       this.messageHandler = messageHandler;
  497.  
  498.       messageHandler.on('GetDoc', function transportDoc(data) {
  499.         var pdfInfo = data.pdfInfo;
  500.         var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
  501.         this.pdfDocument = pdfDocument;
  502.         this.workerReadyPromise.resolve(pdfDocument);
  503.       }, this);
  504.  
  505.       messageHandler.on('NeedPassword', function transportPassword(data) {
  506.         this.workerReadyPromise.reject(data.exception.message, data.exception);
  507.       }, this);
  508.  
  509.       messageHandler.on('IncorrectPassword', function transportBadPass(data) {
  510.         this.workerReadyPromise.reject(data.exception.message, data.exception);
  511.       }, this);
  512.  
  513.       messageHandler.on('InvalidPDF', function transportInvalidPDF(data) {
  514.         this.workerReadyPromise.reject(data.exception.name, data.exception);
  515.       }, this);
  516.  
  517.       messageHandler.on('UnknownError', function transportUnknownError(data) {
  518.         this.workerReadyPromise.reject(data.exception.message, data.exception);
  519.       }, this);
  520.  
  521.       messageHandler.on('GetPage', function transportPage(data) {
  522.         var pageInfo = data.pageInfo;
  523.         var page = new PDFPageProxy(pageInfo, this);
  524.         this.pageCache[pageInfo.pageIndex] = page;
  525.         var promise = this.pagePromises[pageInfo.pageIndex];
  526.         promise.resolve(page);
  527.       }, this);
  528.  
  529.       messageHandler.on('GetAnnotations', function transportAnnotations(data) {
  530.         var annotations = data.annotations;
  531.         var promise = this.pageCache[data.pageIndex].annotationsPromise;
  532.         promise.resolve(annotations);
  533.       }, this);
  534.  
  535.       messageHandler.on('RenderPage', function transportRender(data) {
  536.         var page = this.pageCache[data.pageIndex];
  537.         var depFonts = data.depFonts;
  538.  
  539.         page.stats.timeEnd('Page Request');
  540.         page.startRenderingFromOperatorList(data.operatorList, depFonts);
  541.       }, this);
  542.  
  543.       messageHandler.on('commonobj', function transportObj(data) {
  544.         var id = data[0];
  545.         var type = data[1];
  546.         if (this.commonObjs.hasData(id))
  547.           return;
  548.  
  549.         switch (type) {
  550.           case 'Font':
  551.             var exportedData = data[2];
  552.  
  553.             // At this point, only the font object is created but the font is
  554.             // not yet attached to the DOM. This is done in `FontLoader.bind`.
  555.             var font;
  556.             if ('error' in exportedData)
  557.               font = new ErrorFont(exportedData.error);
  558.             else
  559.               font = new Font(exportedData);
  560.             this.commonObjs.resolve(id, font);
  561.             break;
  562.           default:
  563.             error('Got unknown common object type ' + type);
  564.         }
  565.       }, this);
  566.  
  567.       messageHandler.on('obj', function transportObj(data) {
  568.         var id = data[0];
  569.         var pageIndex = data[1];
  570.         var type = data[2];
  571.         var pageProxy = this.pageCache[pageIndex];
  572.         if (pageProxy.objs.hasData(id))
  573.           return;
  574.  
  575.         switch (type) {
  576.           case 'JpegStream':
  577.             var imageData = data[3];
  578.             loadJpegStream(id, imageData, pageProxy.objs);
  579.             break;
  580.           case 'Image':
  581.             var imageData = data[3];
  582.             pageProxy.objs.resolve(id, imageData);
  583.  
  584.             // heuristics that will allow not to store large data
  585.             var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  586.             if ('data' in imageData &&
  587.                 imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  588.               pageProxy.cleanupAfterRender = true;
  589.             }
  590.             break;
  591.           default:
  592.             error('Got unknown object type ' + type);
  593.         }
  594.       }, this);
  595.  
  596.       messageHandler.on('DocProgress', function transportDocProgress(data) {
  597.         this.workerReadyPromise.progress({
  598.           loaded: data.loaded,
  599.           total: data.total
  600.         });
  601.       }, this);
  602.  
  603.       messageHandler.on('DocError', function transportDocError(data) {
  604.         this.workerReadyPromise.reject(data);
  605.       }, this);
  606.  
  607.       messageHandler.on('PageError', function transportError(data) {
  608.         var page = this.pageCache[data.pageNum - 1];
  609.         if (page.displayReadyPromise)
  610.           page.displayReadyPromise.reject(data.error);
  611.         else
  612.           error(data.error);
  613.       }, this);
  614.  
  615.       messageHandler.on('JpegDecode', function(data, promise) {
  616.         var imageData = data[0];
  617.         var components = data[1];
  618.         if (components != 3 && components != 1)
  619.           error('Only 3 component or 1 component can be returned');
  620.  
  621.         var img = new Image();
  622.         img.onload = (function messageHandler_onloadClosure() {
  623.           var width = img.width;
  624.           var height = img.height;
  625.           var size = width * height;
  626.           var rgbaLength = size * 4;
  627.           var buf = new Uint8Array(size * components);
  628.           var tmpCanvas = createScratchCanvas(width, height);
  629.           var tmpCtx = tmpCanvas.getContext('2d');
  630.           tmpCtx.drawImage(img, 0, 0);
  631.           var data = tmpCtx.getImageData(0, 0, width, height).data;
  632.  
  633.           if (components == 3) {
  634.             for (var i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  635.               buf[j] = data[i];
  636.               buf[j + 1] = data[i + 1];
  637.               buf[j + 2] = data[i + 2];
  638.             }
  639.           } else if (components == 1) {
  640.             for (var i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  641.               buf[j] = data[i];
  642.             }
  643.           }
  644.           promise.resolve({ data: buf, width: width, height: height});
  645.         }).bind(this);
  646.         var src = 'data:image/jpeg;base64,' + window.btoa(imageData);
  647.         img.src = src;
  648.       });
  649.     },
  650.  
  651.     fetchDocument: function WorkerTransport_fetchDocument(source) {
  652.       this.messageHandler.send('GetDocRequest', {source: source});
  653.     },
  654.  
  655.     getData: function WorkerTransport_getData(promise) {
  656.       this.messageHandler.send('GetData', null, function(data) {
  657.         promise.resolve(data);
  658.       });
  659.     },
  660.  
  661.     getPage: function WorkerTransport_getPage(pageNumber, promise) {
  662.       var pageIndex = pageNumber - 1;
  663.       if (pageIndex in this.pagePromises)
  664.         return this.pagePromises[pageIndex];
  665.       var promise = new PDFJS.Promise('Page ' + pageNumber);
  666.       this.pagePromises[pageIndex] = promise;
  667.       this.messageHandler.send('GetPageRequest', { pageIndex: pageIndex });
  668.       return promise;
  669.     },
  670.  
  671.     getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
  672.       this.messageHandler.send('GetAnnotationsRequest',
  673.         { pageIndex: pageIndex });
  674.     }
  675.   };
  676.   return WorkerTransport;
  677.  
  678. })();
Advertisement
Add Comment
Please, Sign In to add comment