generated from NaverPayDev/ts-monorepo-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e649313
commit e03363a
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, {useEffect, useState} from 'react' | ||
|
||
import {getPdfDocument} from '../dist/cjs' | ||
import * as pdfjs from '../dist/cjs/pdf' | ||
|
||
import type {PDFDocumentProxy} from '../src/pdfjs-dist/types/pdfjs' | ||
|
||
const meta = { | ||
title: 'React PDF', | ||
component: 기본_SVG, | ||
} | ||
export default meta | ||
|
||
const PDF_URL = | ||
'https://fs.pstatic.net/contents/resource/loan/personal-compare/required/0/1668583261818/gi_creditLoanNF_02.pdf' | ||
|
||
export function 기본_SVG() { | ||
const [pdfInfo, setPdfInfo] = useState<PDFDocumentProxy | undefined>() | ||
|
||
useEffect(() => { | ||
;(async () => { | ||
const pdf = await getPdfDocument({file: PDF_URL}) | ||
setPdfInfo(pdf) | ||
})() | ||
}, []) | ||
|
||
if (!pdfInfo) { | ||
return null | ||
} | ||
|
||
return ( | ||
<> | ||
{Array.from({length: pdfInfo.numPages}).map((_, index) => { | ||
return ( | ||
<div | ||
key={index} | ||
ref={async (node) => { | ||
if (!node) { | ||
return | ||
} | ||
const page = await pdfInfo.getPage(index + 1) | ||
const viewport = page.getViewport({scale: 1, rotation: 0}) | ||
const operatorList = await page.getOperatorList() | ||
|
||
node.setAttribute('width', `${viewport.width}px`) | ||
node.setAttribute('height', `${viewport.height}px`) | ||
|
||
const svgGfx = new pdfjs.SVGGraphics(page.commonObjs, page.objs) | ||
const svg = await svgGfx.getSVG(operatorList, viewport) | ||
node.appendChild(svg) | ||
}} | ||
/> | ||
) | ||
})} | ||
</> | ||
) | ||
} |