๊ตฌ์ฑ:
๋ฌธ์ ๋ฅผ ์ฌํํ๋ ๋จ๊ณ:
function onmessage () {
const pdfDocument = await pdfjs.getDocument('/some-hard-coded.pdf')
const page = await pdfDocument.getPage(1)
const viewport = pdfPage.getViewport(1)
const width = 250
const height = viewport.height * (width / viewport.width)
const canvas = new OffscreenCanvas(width, height)
const canvasContext = canvas.getContext('2d', { alpha: false })
return page.render({ canvasContext, viewport })
})
w = new Worker('sample-pdf.js');
์ ๊ฐ์ด ํธ์ถํ์ธ์.์์๋๋ ๋์์ ๋ฌด์์ ๋๊น? (์คํฌ๋ฆฐ์ท ์ถ๊ฐ)
PDF๋ OffscreenCanvas
๋ ๋๋ง๋ฉ๋๋ค.
๋ฌด์์ด ์๋ชป๋์๋์? (์คํฌ๋ฆฐ์ท ์ถ๊ฐ)
ReferenceError: ๋ฌธ์๊ฐ ์ ์๋์ง ์์์ต๋๋ค.
GenericFontLoader.insertRule(pdf.js:10154)
GenericFontLoader.bind์์ (pdf.js:10205)
WorkerTransport์์(pdf.js:9177)
LoopbackPort.MessageHandler._onComObjOnMessage์์ (pdf.js:12833)
๋ฃจํ๋ฐฑํฌํธ์์.(pdf.js:8681)
Array.forEach์์ ()
์ฆ ์ด๊ฒ์ ์คํจํ๊ณ ์์ต๋๋ค.
styleElement = this.styleElement = document.createElement('์คํ์ผ');
๋ฌธ์ ๋ DOM์ด ์๋ค๋ ๊ฒ์ ๋๋ค. PDF.js์ Node ์์ ๊ฐ ์๋ ๊ฒ์ฒ๋ผ ๋ฌธ์ ๋ ๋ฌธ์ ์ค ํ๋์ผ ์ ์์ต๋๋ค. ๋๋ ๊น์ ๊ณณ์ ์จ์ด ์๋ ๋ฌธ์ ๊ฐ ์์ ์ ์์ต๋๋ค. ์ด์จ๋ ์ฌ๊ธฐ์ ๋ช ๊ฐ์ง ๋ถ๋ช ํ ์ง์นจ์ด ์๋ ๊ฒฝ์ฐ๋ฅผ ๋๋นํ์ฌ ๋ณด๊ณ ํ๊ณ ์ถ์์ต๋๋ค.
(๋ณธ์ง์ ์ผ๋ก) ๋ฌธ์ #10039์ ๋ณต์ ๋ณธ์ฒ๋ผ ๋ณด์
๋๋ค. OffscreenCanvas
๋ฅผ ์ฆ์ ์ง์ํ๋ ค๋ฉด ์๋นํ ์์ ๋ฆฌํฉํ ๋ง์ด ํ์ํ ๊ฒ์
๋๋ค.
๊ฐ์ฌ ํด์. @Snuffleupagus ๋๋ ๊ทธ ๋ฌธ์ ๋ฅผ ๋ณด์๊ณ ๊ทธ๊ฒ์ ์ฐ๊ฒฐํด์ผํ์ต๋๋ค. ๋ฌธ์ ๋ ๋ค์๊ณผ ๊ฐ์ ์๋ฏธ์์ ๋์ผํ์ง ์์ต๋๋ค.
OffscreenCanvas
๋ ๋ฉ์ธ ์ค๋ ๋์์ ์ฌ์ฉํ ์ ์์ต๋๋ค(์ฆ, ์น ์์
์์๋ง ๊ตญํ๋์ง ์์).์ฆ, OffscreenCanvas
์ง์์ CanvasElement
๋ํ ๋์์ด ๋ ์ ์๋ ๋ ๋ค๋ฅธ ๋ฌธ์ ์ด์ง๋ง ๊ทธ๊ฒ๋ง์ผ๋ก๋ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ์ ์ถฉ๋ถํ์ง ์์ ์ ์์ต๋๋ค.
https://github.com/mozilla/pdf.js/blob/master/examples/node/pdf2png/pdf2png.js (๋
ธ๋ ์)๋ฅผ ๋ณด๋ฉด canvasFactory
, ๋. ๊ทธ๋ ๊ฒ ํ๋ฉด ์ด๋ป๊ฒ ๋๋์?
์น ์์ ์ ๋ด์์ pdf.js๋ฅผ ์ด๋ป๊ฒ ์ฌ์ฉํฉ๋๊น?
์ด๊ฑธ๋ก ์์ ํ์ต๋๋ค.
// Worker.ts
import { pdfjs } from "react-pdf";
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;
pdfjs.getDocument(...) => errors
๊ทธ๋ฌ๋ getDocument
. ๊ทธ๊ฒ์ ์ค๋ฅ๋ฅผ ๋ฐํ
์กํ์ง ์์(์ฝ์ ์ค) ์ค๋ฅ: ๊ฐ์ง ์์ ์ ์ค์ ์คํจ: "__webpack_require__(...).ensure๋ ํจ์๊ฐ ์๋๋๋ค"
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์น ์์ ์ ๋ด์์ pdf.js๋ฅผ ์ด๋ป๊ฒ ์ฌ์ฉํฉ๋๊น?
์ด๊ฑธ๋ก ์์ ํ์ต๋๋ค.
๊ทธ๋ฌ๋
getDocument
. ๊ทธ๊ฒ์ ์ค๋ฅ๋ฅผ ๋ฐํ