Skip to content

Commit

Permalink
[#21] 기본 추가되었던 핸들러 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
2-one-week committed May 17, 2024
1 parent c7b26d2 commit 48fc50b
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions packages/react-pdf/src/components/PdfViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type PDFViewerProps = PdfRenderProps & {
* pdf load 및 rendering 관련 callback
*/
onLoadPDFRender?: () => void
onErrorPDFRender?: (e: Error) => void
onErrorPDFRender?: (e: unknown) => void
/**
* pdf 외 rendering 할 컴포넌트
*/
Expand All @@ -45,6 +45,8 @@ export function PDFViewer({
header,
footer,
lazyLoading = true,
onLoadPDFRender,
onErrorPDFRender,
...options
}: PDFViewerProps) {
const [pdf, setPdf] = useState<PDFDocumentProxy | undefined>()
Expand All @@ -53,20 +55,25 @@ export function PDFViewer({

useIsomorphicLayoutEffect(() => {
async function init() {
const pdfDocument = await getPdfDocument({
file: pdfUrl,
/**
* 오래된 파일의 경우 cmap을 custom하게 지원
*/
...(options?.cMapUrl ? {cMapUrl: options.cMapUrl} : {}),
...(options?.cMapCompressed ? {cMapPacked: options.cMapCompressed} : {}),
/**
* header 설정
*/
...(options?.withCredentials ? {withCredentials: options.withCredentials} : {}),
})
if (!pdf || pdf.fingerprint !== pdfDocument.fingerprint) {
setPdf(pdfDocument)
try {
const pdfDocument = await getPdfDocument({
file: pdfUrl,
/**
* 오래된 파일의 경우 cmap을 custom하게 지원
*/
...(options?.cMapUrl ? {cMapUrl: options.cMapUrl} : {}),
...(options?.cMapCompressed ? {cMapPacked: options.cMapCompressed} : {}),
/**
* header 설정
*/
...(options?.withCredentials ? {withCredentials: options.withCredentials} : {}),
})
if (!pdf || pdf.fingerprint !== pdfDocument.fingerprint) {
setPdf(pdfDocument)
}
onLoadPDFRender?.()
} catch (error) {
onErrorPDFRender?.(error)
}
}
init()
Expand Down

0 comments on commit 48fc50b

Please sign in to comment.