๋ณธ๋ฌธ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

PdfViewer

๐Ÿšจ Warningโ€‹

  • ์Šคํƒ€์ผ์ด ์ ์šฉ๋œ PdfViewer๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”, PdfViewer๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํŒŒ์ผ ์ตœ์ƒ๋‹จ์— import '@naverpay/react-pdf/index.css' ์ถ”๊ฐ€๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ•โ€‹

  • ๋‹จ์ˆœ PDF Viewer๋งŒ ํ•„์š”ํ•œ ๊ฒฝ์šฐ (์ฆ‰, pdf text์— ๋”ฐ๋ฅธ handler๊ฐ€ ํ•„์š” ์—†๋Š” ๊ฒฝ์šฐ) ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

React (CSR / SSR)โ€‹

import {PdfViewer} from '@naverpay/react-pdf'

function SomeComponent () {
return <PdfViewer pdfUrl={"pdfUrl"} onErrorPDFRender={onErrorPDFRender} />
}

Advanced Usageโ€‹

Click Handler ๊ฐ€ ํ•„์š”ํ•œ ๊ฒฝ์šฐโ€‹

import {PdfViewer} from '@naverpay/react-pdf'


function SomeComponent() {
return (
<PdfViewer
pdfUrl={pdfUrl}
onClickWords={[{target: '์•ฝ๊ด€', callback: () => alert('์•ฝ๊ด€์„ ํด๋ฆญํ–ˆ์Šต๋‹ˆ๋‹ค.')}]}
/>
)
}

์ƒ/ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ rendering์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐโ€‹

import {PdfViewer} from '@naverpay/react-pdf'

function PdfViewer() {
return (
<PdfViewer
pdfUrl={pdfUrl}
onErrorPDFRender={onErrorPDFRender}
header={<>์ƒ์œ„์— ๋ Œ๋”๋ง๋  ์ปดํฌ๋„ŒํŠธ</>}
footer={<>ํ•˜์œ„์— ๋ Œ๋”๋ง๋  ์ปดํฌ๋„ŒํŠธ</>}
/>
)
}

PdfViewer์— ์ฃผ์ž…๋˜๋Š” Propsโ€‹

props์„ค๋ช…ํƒ€์ž…๊ธฐํƒ€
pdfUrl๋…ธ์ถœํ•˜๊ณ ์ž ํ•˜๋Š” PDF์˜ ๋งํฌ / File Path

local, cdn ๋ชจ๋‘ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. local ์ œ๊ณต์‹œ, base path์— ์œ ์˜ํ•ด์ฃผ์„ธ์š”.
stringrequired
cMapUrl์‚ฌ์šฉํ•  PDF์— ์ง€์›ํ•˜์ง€ ์•Š๋Š” ํฐํŠธ๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ์—, camp์ด ์—…๋กœ๋“œ๋œ url ์ฃผ์†Œ๋ฅผ ์ ์–ด์ฃผ์„ธ์š”.stringoptional
cMapCompressed์‚ฌ์šฉํ•  PDF์— ์ง€์›ํ•˜์ง€ ์•Š๋Š” ํฐํŠธ๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ์—, ์••์ถ• ์—ฌ๋ถ€๋ฅผ ์ ์–ด์ฃผ์„ธ์š”.booleanoptional
withCredentialsurl์„ ํ†ตํ•œ pdf ์š”์ฒญ ์‹œ, header์™€ ๊ฐ™์ด ์š”์ฒญํ• ๊ฑด์ง€์— ๋Œ€ํ•œ ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.booleanoptional
onClickWords์•ฝ๊ด€์ด๋‚˜ ์–ด๋–ค ๋‹ค๋ฅธ Click ์•ก์…˜์— ๋”ฐ๋ฅธ ํ˜•์ƒ์ด ํ•„์š”ํ• ๋•Œ, ์ฃผ์ž…ํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
์›ํ•˜๋Š” ๋‹จ์–ด๋ฅผ target์—, target click ํ›„ ์ทจํ•  ์•ก์…˜์„ callback์„ ๋„ฃ์–ด์ฃผ์„ธ์š”.

target์€ string, ์ •๊ทœ ํ‘œํ˜„์‹์„ ๋ชจ๋‘ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿšจ ์ฃผ์˜ ๐Ÿšจ
ํ•ด๋‹น props๊ฐ€ ์กด์žฌํ•˜๋ฉด, ์ž๋™์œผ๋กœ ์–ด์ ˆ ๋‹จ์œ„๋ฅผ ๋Š์Šต๋‹ˆ๋‹ค.
@naverpay/react-pdf๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ PDF๋ฅผ ํšจ์œจ์ ์œผ๋กœ ๋ Œ๋”๋งํ•˜๊ธฐ ์œ„ํ•ด, ํ•œ๋ฌธ์žฅ ๋‹จ์œ„๋กœ ๋ Œ๋”๋งํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
react-pdf๊ฐ€ ์ œ๊ณตํ•˜๋Š” ๊ธฐ๋Šฅ์ด ์•„๋‹Œ, space๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ž๋ฅด๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. (์ •ํ™•ํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.) ์–ด์ ˆ ๋‹จ์œ„๋กœ ๋Š๊ธฐ์ง€ ์•Š๋Š” pdf๊ฐ€ ์กด์žฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
Array<{target: string | RegExp; callback: () => void}>optional
onLoadPDFRenderpdf load ์„ฑ๊ณต handler() => voidoptional
onErrorPDFRenderpdf error handler(e: unknown) => voidoptional
headerPDF ์ƒ์œ„์— rendering ๋  ์ปดํฌ๋„ŒํŠธ๋ฅผ props๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค.ReactNodeoptional
footerPDF ํ•˜์œ„์— rendering ๋  ์ปดํฌ๋„ŒํŠธ๋ฅผ props๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค.ReactNodeoptional

Suggestionโ€‹

onErrorPDFRender๋Š” pdf viewer์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋‚œ ๊ฒฝ์šฐ์— ํŠธ๋ฆฌ๊ฑฐ๋˜๋Š” callback ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.

  • PDF ๋ Œ๋”๋ง ์—๋Ÿฌ์‹œ, pdf๋ฅผ ๋ธŒ๋ผ์šฐ์ € ๊ธฐ๋ณธ PDF viewer๋กœ ์—ด์–ด์ฃผ๋Š” handler ์ž…๋‹ˆ๋‹ค.

  • ํ•˜๋‹จ์˜ handler๋ฅผ ์‚ฌ์šฉํ•ด๋ณด์„ธ์š”.

    const handleRenderPDFError = useCallback(
    (e) => {
    // ๋ธŒ๋ผ์šฐ์ €์—์„œ ๊ธฐ๋ณธ์œผ๋กœ ์ œ๊ณตํ•˜๋Š” pdf viewer๋ฅผ ์ƒˆ์ฐฝ์œผ๋กœ ๋„์šฐ๋„๋ก ์ฒ˜๋ฆฌ
    window.open(pdfUrl, '_blank')
    // error logging
    },
    [pdfFilePath],
    )