pdfJsLoader.js 1.4 KB

12345678910111213141516171819202122232425262728
  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. /*
  12. * Adapted from https://github.com/mozilla/pdfjs-dist/blob/e9492b7a725ec4edd466880223474f4295a5fb45/webpack.js
  13. * The PDF.js worker needs to be loaded in a Web Worker. This can be done
  14. * automatically with webpack via worker-loader.
  15. * PDF.js has the above file to do this, however it uses the webpack loader
  16. * module loading syntax, which prevents us from customising the loader.
  17. * We need to output the worker file to the public/js directory, and so we need
  18. * to customise the loader's options. However the rest of the file is identical
  19. * to the one provided by PDF.js.
  20. */
  21. var pdfjs = require('pdfjs-dist/build/pdf.js')
  22. var PdfjsWorker = require('pdfjs-dist/build/pdf.worker.js')
  23. if (typeof window !== 'undefined' && 'Worker' in window) {
  24. pdfjs.GlobalWorkerOptions.workerPort = new PdfjsWorker()
  25. }
  26. module.exports = pdfjs