pdfJsLoader.js 836 B

123456789101112131415161718
  1. /*
  2. * Adapted from https://github.com/mozilla/pdfjs-dist/blob/e9492b7a725ec4edd466880223474f4295a5fb45/webpack.js
  3. * The PDF.js worker needs to be loaded in a Web Worker. This can be done
  4. * automatically with webpack via worker-loader.
  5. * PDF.js has the above file to do this, however it uses the webpack loader
  6. * module loading syntax, which prevents us from customising the loader.
  7. * We need to output the worker file to the public/js directory, and so we need
  8. * to customise the loader's options. However the rest of the file is identical
  9. * to the one provided by PDF.js.
  10. */
  11. var pdfjs = require('pdfjs-dist/build/pdf.js')
  12. var PdfjsWorker = require('pdfjs-dist/build/pdf.worker.js')
  13. if (typeof window !== 'undefined' && 'Worker' in window) {
  14. pdfjs.GlobalWorkerOptions.workerPort = new PdfjsWorker()
  15. }
  16. module.exports = pdfjs