{"_id":"@bastienmoulia/pdf.js-dist","_rev":"1-2de665178ecc85543a6441eae160f96e","name":"@bastienmoulia/pdf.js-dist","description":"Compiled version of pdf.js","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"author":"","bugs":{"url":"https://github.com/legalthings/pdf.js-dist/issues"},"bundleDependencies":false,"deprecated":false,"description":"Compiled version of pdf.js","devDependencies":{"css-prefix":"git+https://github.com/moesjarraf/css-prefix.git#0.0.2+moesjarraf.3","grunt":"^0.4.5"},"homepage":"https://github.com/legalthings/pdf.js-dist#readme","keywords":["pdf"],"license":"Apache-2.0","main":"pdf.js","name":"@bastienmoulia/pdf.js-dist","repository":{"type":"git","url":"git+https://github.com/legalthings/pdf.js-dist.git"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"version":"0.1.0","_id":"@bastienmoulia/pdf.js-dist@0.1.0","_npmVersion":"5.2.0","_nodeVersion":"8.1.2","_npmUser":{"name":"bastienmoulia","email":"bmoulia@gmail.com"},"dist":{"integrity":"sha512-5SsuQ5AbokGReynJHoRvVAumX1pMUCIxuf1jGRzKm4EnBJISBfvnJ1BsxdBmwxjTDYBnlSL1dxPCMMJqeZqOLA==","shasum":"c784534e6f5f3092b7823124f0a3694ab7bddead","tarball":"https://registry.npmjs.org/@bastienmoulia/pdf.js-dist/-/pdf.js-dist-0.1.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEkm/tRO7zHn+Xhxwn4nZ0G2vEmeJgEsFGGXhoAp/r4xAiEA7VUXjXcpGOza1085pJYc/9LnehOaYpdCSzeR5ar5TjY="}]},"maintainers":[{"name":"bastienmoulia","email":"bmoulia@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/pdf.js-dist-0.1.0.tgz_1503568921714_0.9936702232807875"}}},"readme":"# PDF.js viewer\r\n\r\n[PDF.js](https://mozilla.github.io/pdf.js/) is a Portable Document Format (PDF) library that is built with HTML5.\r\n\r\nThis is a build version of the PDF.js, including the viewer.\r\n\r\n\r\n## Installation\r\n\r\n    bower install pdf.js-viewer\r\n\r\n## Usage\r\n\r\nInclude `viewer.html` using [SSI](http://httpd.apache.org/docs/2.4/howto/ssi.html) or your favorite templating system.\r\n\r\n```html\r\n<html>\r\n  <head>\r\n    <title>PDF.js viewer</title>\r\n    <script src=\"bower_components/pdf.js-viewer/pdf.js\"></script>\r\n    <link rel=\"stylesheet\" href=\"bower_components/pdf.js-viewer/viewer.css\">\r\n    \r\n    <style>\r\n      html, body {\r\n        height: 100%;\r\n        margin: 0;\r\n        padding: 0;\r\n      }\r\n    </style>\r\n  </head>\r\n\r\n  <body>\r\n    <div class=\"pdfjs\">\r\n      <!--#include virtual=\"bower_components/pdf.js-viewer/viewer.html\" --> \r\n    </div>\r\n\r\n    <script>\r\n      PDFJS.webViewerLoad('some-document.pdf');\r\n    </script>\r\n  </body>\r\n</html>\r\n```\r\n\r\n## Upgrading the source\r\n\r\nNormally mozilla's PDF js viewer, will only run as standalone. This version is patched so you can include it within a\r\npage.\r\n\r\nTo update this version, get the pdf.js source code and build the project\r\n\r\n    git clone https://github.com/mozilla/pdf.js.git\r\n    cd pdf.js\r\n    npm install\r\n    node make generic\r\n    cd ..\r\n\r\nAnd update the files from source and patch them\r\n\r\n    cd pdf.js-viewer\r\n    npm install\r\n    ./build.sh ../pdf.js/build/generic/\r\n\r\n### Manual patching\r\n\r\nWhen updating to a new minor (or major) version, it's likely than one or more of the chunks can't be applied. This\r\nmeans you need to do these modifications manually.\r\n\r\n\r\n#### function getL10nData()\r\n\r\nThe viewer uses `l10n.js` with a `<link rel=\"resource\" type=\"application/l10n\">` header for internationalization. This\r\nchunk makes using that optional.\r\n\r\n       function getL10nData(key, args, fallback) {\r\n         var data = gL10nData[key];\r\n         if (!data) {\r\n    -      console.warn('#' + key + ' is undefined.');\r\n    +      if (Object.keys(gL10nData).length > 0) {\r\n    +        console.warn('#' + key + ' is undefined.');\r\n    +      }\r\n           if (!fallback) {\r\n             return null;\r\n           }\r\n\r\n#### Dynamic paths\r\n\r\nThe viewer uses relative paths to JavaScript files. This doesn't work when the viewer is embedded on a web page.\r\nInstead the paths are determined based on the path of the current JavaScript file.\r\n\r\n    -PDFJS.imageResourcesPath = './images/';\r\n    -  PDFJS.workerSrc = '../build/pdf.worker.js';\r\n    -  PDFJS.cMapUrl = '../web/cmaps/';\r\n    -  PDFJS.cMapPacked = true;\r\n    +var scriptTagContainer = document.body ||\r\n    +                         document.getElementsByTagName('head')[0];\r\n    +var pdfjsSrc = scriptTagContainer.lastChild.src;\r\n    +\r\n    +if (pdfjsSrc) {\r\n    +  PDFJS.imageResourcesPath = pdfjsSrc.replace(/pdf\\.js$/i, 'images/');\r\n    +  PDFJS.workerSrc = pdfjsSrc.replace(/pdf\\.js$/i, 'pdf.worker.js');\r\n    +  PDFJS.cMapUrl = pdfjsSrc.replace(/pdf\\.js$/i, 'cmaps/');\r\n    +}\r\n    +\r\n    +PDFJS.cMapPacked = true;\r\n\r\n#### Explicitly load a PDF document\r\n\r\nThe viewer shouldn't start loading a (default) document when it's loaded. Instead we want to expose the initialization,\r\nso it can be called in JavaScript with `PDFJS.webViewerLoad()`.\r\n\r\n    -document.addEventListener('DOMContentLoaded', webViewerLoad, true);\r\n    +// document.addEventListener('DOMContentLoaded', webViewerLoad, true);\r\n    +PDFJS.webViewerLoad = function (src) {\r\n    +  if (src) DEFAULT_URL = src;\r\n    +\r\n    +  webViewerLoad();\r\n    +}\r\n\r\nOn several places the code assumes that a PDF is loaded, which (because of the explicit load) might not be the case. We\r\nneed to check if `pdfDocument` is set before using it.\r\n\r\n##### PDFViewerApplication.pagesCount() and PDFLinkService.pagesCount()\r\n\r\n         get pagesCount() {\r\n    -      return this.pdfDocument.numPages;\r\n    +      return this.pdfDocument ? this.pdfDocument.numPages : 0;\r\n         },\r\n\r\n_The pagesCount method for both `PDFViewerApplication` and `PDFLinkService`. Both need to be patched._\r\n\r\n##### PDFViewerApplication.cleanup()\r\n\r\n       cleanup: function pdfViewCleanup() {\r\n         this.pdfViewer.cleanup();\r\n         this.pdfThumbnailViewer.cleanup();\r\n    -    this.pdfDocument.cleanup();\r\n    +    if (this.pdfDocument) {\r\n    +      this.pdfDocument.cleanup();\r\n    +    }\r\n       },\r\n\r\n#### overlayManagerRegister\r\n\r\nThe overlay is registered when the viewer is loaded. The original code will only do this once and give an error on each\r\nsubsequent call. Escpecially with single-page applications (eg an Angular app), the viewer may be loaded multiple times.\r\nThis patch causes pdf.js to unregister an unusued (closed) overlay.\r\n\r\n       register: function overlayManagerRegister(name, callerCloseMethod, canForceClose) {\r\n         return new Promise(function (resolve) {\r\n           var element, container;\r\n           if (!name || !(element = document.getElementById(name)) ||\r\n               !(container = element.parentNode)) {\r\n             throw new Error('Not enough parameters.');\r\n           } else if (this.overlays[name]) {\r\n    -        throw new Error('The overlay is already registered.');\r\n    +        if (this.active !== name) {\r\n    +          this.unregister(name);\r\n    +        } else {\r\n    +          throw new Error('The overlay is already registered and active.');\r\n    +        }\r\n           }\r\n\r\n#### webViewerChange trigger on file upload dialog\r\n\r\nWhenever a file dialog is used (so with any `<input type=\"file\">` on the page), the file is loaded into the pdf.js\r\nviewer. We don't want this behaviour, so comment it out.\r\n\r\n    -window.addEventListener('change', function webViewerChange(evt) {\r\n    +/*window.addEventListener('change', function webViewerChange(evt) {\r\n       var files = evt.target.files;\r\n       if (!files || files.length === 0) {\r\n         return;\r\n    @@ -17627,7 +17647,7 @@\r\n         setAttribute('hidden', 'true');\r\n       document.getElementById('download').setAttribute('hidden', 'true');\r\n       document.getElementById('secondaryDownload').setAttribute('hidden', 'true');\r\n    -}, true);\r\n    +}, true);*/\r\n\r\n#### handleMouseWheel()\r\n\r\nThe JavaScript pdf.js file might be loaded while the viewer isn't being displayed. This causes an error on mouse move.\r\nWe need to check if the viewer is initialized, before handling the event.\r\n\r\n     function handleMouseWheel(evt) {\r\n    +  // Ignore mousewheel event if pdfViewer isn't loaded\r\n    +  if (!PDFViewerApplication.pdfViewer) return;\r\n\r\n#### Load code for worker using AJAX if needed\r\n\r\nA [Web Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) can't use code from\r\na same-origin domain. The CORS headers don't apply.\r\n\r\nhe patch will cause pdf.js to first try to create the Worker the regular way, with a URL to the JavaScript source. If\r\nthis fails, the source if fetched using AJAX and used to create an\r\n[object url](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL). If this also fails, pdf.js will go\r\nonto it's last resort by calling `setupFakeWorker()`.\r\n\r\n    +    /**\r\n    +     * Needed because workers cannot load scripts outside of the current origin (as of firefox v45).\r\n    +     * This patch does require the worker script to be served with a (Access-Control-Allow-Origin: *) header\r\n    +     * @patch\r\n    +     */\r\n    +    var loadWorkerXHR = function(){\r\n    +      var url = PDFJS.workerSrc;\r\n    +      var jsdfd = PDFJS.createPromiseCapability();\r\n    +\r\n    +      if (url.match(/^blob:/) || typeof URL.createObjectURL === 'undefined') {\r\n    +        jsdfd.reject(); // Failed loading using blob\r\n    +      }\r\n    +\r\n    +      var xmlhttp;\r\n    +      xmlhttp = new XMLHttpRequest();\r\n    +\r\n    +      xmlhttp.onreadystatechange = function(){\r\n    +        if (xmlhttp.readyState != 4) return;\r\n    +\r\n    +        if (xmlhttp.status == 200) {\r\n    +          info('Loaded worker source through XHR.');\r\n    +          var workerJSBlob = new Blob([xmlhttp.responseText], { type: 'text/javascript' });\r\n    +          jsdfd.resolve(window.URL.createObjectURL(workerJSBlob));\r\n    +        } else {\r\n    +          jsdfd.reject();\r\n    +        }\r\n    +      };\r\n    +\r\n    +      xmlhttp.open('GET', url, true);\r\n    +      xmlhttp.send();\r\n    +      return jsdfd.promise;\r\n    +    }\r\n    +\r\n    +    var workerError = function() {\r\n    +      loadWorkerXHR().then(function(blob) {\r\n    +        PDFJS.workerSrc = blob;\r\n    +        loadWorker();\r\n    +      }, function() {\r\n    +        this.setupFakeWorker();\r\n    +      }.bind(this));\r\n    +    }.bind(this);\r\n    +\r\n    \r\n    -    if (!globalScope.PDFJS.disableWorker && typeof Worker !== 'undefined') {\r\n    +    var loadWorker = function() {\r\n           var workerSrc = PDFJS.workerSrc;\r\n           if (!workerSrc) {\r\n             error('No PDFJS.workerSrc specified');\r\n    @@ -3559,6 +3603,8 @@\r\n             // Some versions of FF can't create a worker on localhost, see:\r\n             // https://bugzilla.mozilla.org/show_bug.cgi?id=683280\r\n             var worker = new Worker(workerSrc);\r\n    +        worker.onerror = workerError;\r\n    +\r\n             var messageHandler = new MessageHandler('main', worker);\r\n             this.messageHandler = messageHandler;\r\n    \r\n    @@ -3589,11 +3635,16 @@\r\n             return;\r\n           } catch (e) {\r\n             info('The worker has been disabled.');\r\n    +        workerError();\r\n           }\r\n    -    }\r\n    +    }.bind(this);\r\n         // Either workers are disabled, not supported or have thrown an exception.\r\n         // Thus, we fallback to a faked worker.\r\n    -    this.setupFakeWorker();\r\n    +    if (!globalScope.PDFJS.disableWorker && typeof Worker !== 'undefined') {\r\n    +      loadWorker();\r\n    +    } else {\r\n    +      this.setupFakeWorker();\r\n    +    }\r\n       }\r\n\r\n","maintainers":[{"name":"bastienmoulia","email":"bmoulia@gmail.com"}],"time":{"modified":"2022-04-04T17:47:22.644Z","created":"2017-08-24T10:02:03.640Z","0.1.0":"2017-08-24T10:02:03.640Z"},"homepage":"https://github.com/legalthings/pdf.js-dist#readme","keywords":["pdf"],"repository":{"type":"git","url":"git+https://github.com/legalthings/pdf.js-dist.git"},"bugs":{"url":"https://github.com/legalthings/pdf.js-dist/issues"},"license":"Apache-2.0","readmeFilename":"README.md"}