pdf-js-versions.js 1.8 KB

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