if (!fallbackWorkerSrc && λ¬Έμ μ ν !== 'μ μλμ§ μμ') {
var pdfjsFilePath = document.currentScript && document.currentScript.src;
if (pdfjsFilePath) {
fallbackWorkerSrc = pdfjsFilePath.replace(/(.(?:min.)?js)(?.*)?$/i, '.worker$1$2');
}
}
λλλ‘ "document.currentScript" === null, pdfjsFilePath === null,
ν¨μ getWorkerSrc() {
if (_worker_options.GlobalWorkerOptions.workerSrc) {
λ°ν _worker_options.GlobalWorkerOptions.workerSrc;
}
if (fallbackWorkerSrc μ ν !== 'μ μλμ§ μμ') {
fallbackWorkerSrc λ°ν;
}
throw new Error('"GlobalWorkerOptions.workerSrc"κ° μ§μ λμ§ μμμ΅λλ€.');
}
λΉμ μ νμ μ€μ νμ¬, λͺ
μ μ μΌλ‘ μλ₯Ό workerSrcλ₯Ό μ§μ ν΄μΌν©λλ€ pdfjsLib.GlobalWorkerOptions.workerSrc
νΈμΆνκΈ° μ μ pdfjsLib.getDocument
λ체 λͺ¨λ μν©μμ μ λλ‘ μλνμ§ μμ κ²½μ°μλ§ μ΅μ μ λ
Έλ ₯ μ루μ
μ΄κΈ° λλ¬Έμ.
λ€μμ μλν΄μΌ ν©λλ€.
const pdfjs = await import('pdfjs-dist/build/pdf');
const pdfjsWorker = await import('pdfjs-dist/build/pdf.worker.entry');
pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;
...
λ€μμ μλν΄μΌ ν©λλ€.
const pdfjs = await import('pdfjs-dist/build/pdf'); const pdfjsWorker = await import('pdfjs-dist/build/pdf.worker.entry'); pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker; ...
λλ λΉμ μ΄ λ°μμμ μ€ μμ΄λμ΄λ₯Ό μ¬μ©νλ λ° μ΄λ €μμ κ²ͺμμ΅λλ€.
λ¬Έμ λ κ΅¬μ± μμκ° λ§μ΄νΈλ λ μλνμ§ μλλ€λ κ²μ
λλ€.
곡μ μ€ν¬λ¦½νΈλ₯Ό μ¬μ©νλ©΄ λͺ¨λ κ²μ΄ μ μμ΄μ§λ§ pdfjs-dist
μλνμ§ μμ΅λλ€.
const pdfjsLib = window['pdfjs-dist/build/pdf
pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';
κ·Έκ²μ λν μ΄λ€ μμ΄λμ΄? μ€ν¬λ¦½νΈλ₯Ό μ¬μ©νμ§ μλ κ²μ΄ μ’μ΅λλ€.
pdf.jsκ° κ³΅μμ μΌλ‘ λ°μμ μ§μνμ§ μκΈ° λλ¬Έμ pdfλ³΄λ€ λ°μ μΆμνλ₯Ό μ¬μ©νκ² μ΅λλ€.
κ°μ₯ μ μ©ν λκΈ
λ€μμ μλν΄μΌ ν©λλ€.