Pdf.js: ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” API ์‚ฌ์šฉ(์˜ˆ์ œ ํฌํ•จ)

์— ๋งŒ๋“  2018๋…„ 12์›” 24์ผ  ยท  4์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: mozilla/pdf.js

๊ตฌ์„ฑ:

  • ์›น ๋ธŒ๋ผ์šฐ์ € ๋ฐ ๋ฒ„์ „: Firefox 64.0
  • ์šด์˜ ์ฒด์ œ ๋ฐ ๋ฒ„์ „: Windows 10
  • PDF.js ๋ฒ„์ „: '2.6.1'( //mozilla.github.io/pdf.js/build/pdf.js ์ง์ ‘ ํฌํ•จ๋จ)
  • ๋ธŒ๋ผ์šฐ์ € ํ™•์žฅ์ž: ์•„๋‹ˆ์š”

๋ฌธ์ œ๋ฅผ ์žฌํ˜„ํ•˜๋Š” ๋‹จ๊ณ„:
1. ๋‹ค์Œ์„ ํ†ตํ•ด ํฌํ•จ
- <script src="//mozilla.github.io/pdf.js/build/pdf.js"></script>
2. ์„ธํŠธ:
- pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';
3. https://mozilla.github.io/pdf.js/examples/์˜ ์˜ˆ์ œ ์‚ฌ์šฉ

๋ฌด์—‡์ด ์ž˜๋ชป๋˜์—ˆ๋‚˜์š”? (์Šคํฌ๋ฆฐ์ƒท ์ถ”๊ฐ€)

99733b699429b48a9982577efb14fdde

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

v1์—์„œ v2๋กœ ์—…๊ทธ๋ ˆ์ด๋“œํ•  ๋•Œ ์ด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ์—ฌ๊ธฐ์— ์™”์Šต๋‹ˆ๋‹ค.

Deprecated API usage:  PDFDocumentLoadingTask.then method, use the `promise` getter instead.

๊ฐ„๋‹จํžˆ ๋งํ•ด์„œ, ์ด์ œ ๋ช…์‹œ์ ์œผ๋กœ .promise ์ฐธ์กฐํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

//V1
const loadPDF = await PDFJS.getDocument(file);
const pages = loadPDF.numPages;


//V2
const loadPDF = await PDFJS.getDocument(file).promise; //<-- simply change it here
const pages = loadPDF.numPages;

๋ชจ๋“  4 ๋Œ“๊ธ€

์˜ˆ์ œ๋Š” ์ด ์ƒˆ๋กœ์šด API ์‚ฌ์šฉ์œผ๋กœ ์ด๋ฏธ ์—…๋ฐ์ดํŠธ๋˜์—ˆ์ง€๋งŒ ์•„์ง JSFiddle์—์„œ๋Š” ์—…๋ฐ์ดํŠธ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. @yurydelendik examples ํด๋”์˜ ํ˜„์žฌ ์ฝ”๋“œ๋กœ ํ•ด๋‹น ํŽ˜์ด์ง€์˜ ๋ชจ๋“  ์˜ˆ์ œ๋ฅผ ์—…๋ฐ์ดํŠธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ?

๊ฒฐ์ •๋œ

v1์—์„œ v2๋กœ ์—…๊ทธ๋ ˆ์ด๋“œํ•  ๋•Œ ์ด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ์—ฌ๊ธฐ์— ์™”์Šต๋‹ˆ๋‹ค.

Deprecated API usage:  PDFDocumentLoadingTask.then method, use the `promise` getter instead.

๊ฐ„๋‹จํžˆ ๋งํ•ด์„œ, ์ด์ œ ๋ช…์‹œ์ ์œผ๋กœ .promise ์ฐธ์กฐํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

//V1
const loadPDF = await PDFJS.getDocument(file);
const pages = loadPDF.numPages;


//V2
const loadPDF = await PDFJS.getDocument(file).promise; //<-- simply change it here
const pages = loadPDF.numPages;

๋ทฐ ํฌํŠธ ์˜ค๋ฅ˜๋Š” ๋ฒ„์ „ 1 ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
var viewport = pdfPage.getViewport(scale, rotate);

GetViewportParameters๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ๋ณ€๊ฒฝํ•˜์‹ญ์‹œ์˜ค.
https://github.com/mozilla/pdf.js/blob/master/src/display/api.js#L158

var viewport = pdfPage.getViewport({scale:scale, rotate:rotate});

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰