pdf-js-versions.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // NOTE: using "legacy" build as main build requires webpack v5
  2. // import PDFJS from 'pdfjs-dist/webpack'
  3. // To add a new version, copy and adjust one of the `importPDFJS*` functions below,
  4. // add the variant to the "switch" statement, and add to `pdfjsVersions` in webpack.config.js
  5. import 'core-js/features/promise/all-settled' // polyfill for Promise.allSettled (used by pdf.js)
  6. import getMeta from '../../../utils/meta'
  7. async function importPDFJS210() {
  8. const cMapUrl = '/js/pdfjs-dist210/cmaps/'
  9. const imageResourcesPath = '/images/pdfjs-dist210'
  10. const [PDFJS, PDFJSViewer, { default: PDFJSWorker }] = await Promise.all([
  11. import('pdfjs-dist210/legacy/build/pdf'),
  12. import('pdfjs-dist210/legacy/web/pdf_viewer'),
  13. import('pdfjs-dist210/legacy/build/pdf.worker'),
  14. import('pdfjs-dist210/legacy/web/pdf_viewer.css'),
  15. ])
  16. if (typeof window !== 'undefined' && 'Worker' in window) {
  17. PDFJS.GlobalWorkerOptions.workerPort = new PDFJSWorker()
  18. }
  19. return { PDFJS, PDFJSViewer, PDFJSWorker, cMapUrl, imageResourcesPath }
  20. }
  21. async function importPDFJS213() {
  22. const cMapUrl = '/js/pdfjs-dist213/cmaps/'
  23. const imageResourcesPath = '/images/pdfjs-dist213'
  24. const [PDFJS, PDFJSViewer, { default: PDFJSWorker }] = await Promise.all([
  25. import('pdfjs-dist213/legacy/build/pdf'),
  26. import('pdfjs-dist213/legacy/web/pdf_viewer'),
  27. import('pdfjs-dist213/legacy/build/pdf.worker'),
  28. import('pdfjs-dist213/legacy/web/pdf_viewer.css'),
  29. ])
  30. if (typeof window !== 'undefined' && 'Worker' in window) {
  31. PDFJS.GlobalWorkerOptions.workerPort = new PDFJSWorker()
  32. }
  33. return { PDFJS, PDFJSViewer, PDFJSWorker, cMapUrl, imageResourcesPath }
  34. }
  35. async function importPDFJS() {
  36. const variant = getMeta('ol-pdfjsVariant', 'default')
  37. switch (variant) {
  38. case '213':
  39. return importPDFJS213()
  40. case '210':
  41. case 'default':
  42. default:
  43. return importPDFJS210()
  44. }
  45. }
  46. export default importPDFJS()