@@ -7,17 +7,12 @@ import { sendPdfPreviewSuccess, sendPdfPreviewFailed, sendClientError } from '..
77import { useApplicationData } from '@entry/ui' ;
88import { convertGradeToScore } from '../../hooks' ;
99import { toast } from 'react-toastify' ;
10- import { Document , Page , pdfjs } from 'react-pdf' ;
11- import workerUrl from 'pdfjs-dist/build/pdf.worker.min.js?url' ;
12-
13- // PDF worker 설정을 컴포넌트 외부에서 초기화
14- pdfjs . GlobalWorkerOptions . workerSrc = workerUrl ;
1510
1611export const ApplicationPreview = ( ) => {
1712 const [ isLoading , setIsLoading ] = useState < boolean > ( false ) ;
1813 const [ pdfUrl , setPdfUrl ] = useState < string | null > ( null ) ;
19- const [ numPages , setNumPages ] = useState < number | null > ( null ) ;
2014 const hasFetched = useRef ( false ) ;
15+ const iframeRef = useRef < HTMLIFrameElement > ( null ) ;
2116
2217 const formatDate = ( arr : ( number | string ) [ ] , graduationType : string ) => {
2318 // 검정고시는 null 반환
@@ -360,46 +355,30 @@ export const ApplicationPreview = () => {
360355 </ NoticeText >
361356 < ApplicationContainer >
362357 { pdfUrl ? (
363- < PdfViewport >
364- < Document
365- file = { pdfUrl }
366- loading = { < Text color = { colors . gray [ 400 ] } > PDF 로딩중...</ Text > }
367- error = { < Text color = { colors . gray [ 400 ] } > PDF 로딩 실패</ Text > }
368- onLoadError = { ( error ) => {
369- console . error ( 'PDF 로딩 오류:' , error ) ;
370- toast . error ( 'PDF 로딩 실패' ) ;
358+ < PdfIframe
359+ ref = { iframeRef }
360+ src = { pdfUrl }
361+ title = "PDF 미리보기"
362+ onLoad = { ( ) => {
363+ console . log ( 'PDF 로딩 완료' ) ;
364+ } }
365+ onError = { ( e ) => {
366+ console . error ( 'PDF 로딩 오류:' , e ) ;
367+ toast . error ( 'PDF 로딩 실패' ) ;
371368
372- // PDF 렌더링 오류를 클라이언트 에러로 전송
373- sendClientError ( {
374- sessionId : sessionIdRef . current ,
375- pageType : 'USER' ,
376- errorCategory : 'PDF_RENDER_ERROR' ,
377- errorCode : 'ERR_PDF_LOAD' ,
378- message : error ?. message || 'PDF 렌더링 실패' ,
379- stackTrace : error ?. stack ,
380- pageUrl : window . location . pathname ,
381- componentName : 'ApplicationPreview' ,
382- userAction : 'PDF_PREVIEW' ,
383- } ) ;
384- } }
385- onLoadSuccess = { ( info : { numPages : number } ) => setNumPages ( info . numPages ) }
386- options = { {
387- standardFontDataUrl :
'https://unpkg.com/[email protected] /standard_fonts/' , 388- cMapUrl :
'https://unpkg.com/[email protected] /cmaps/' , 389- cMapPacked : true ,
390- } }
391- >
392- { Array . from ( new Array ( numPages || 0 ) , ( _el , index ) => (
393- < Page
394- key = { `page_${ index + 1 } ` }
395- pageNumber = { index + 1 }
396- width = { 794 }
397- renderTextLayer = { false }
398- renderAnnotationLayer = { false }
399- />
400- ) ) }
401- </ Document >
402- </ PdfViewport >
369+ // PDF 렌더링 오류를 클라이언트 에러로 전송
370+ sendClientError ( {
371+ sessionId : sessionIdRef . current ,
372+ pageType : 'USER' ,
373+ errorCategory : 'PDF_RENDER_ERROR' ,
374+ errorCode : 'ERR_PDF_LOAD' ,
375+ message : 'PDF iframe 로딩 실패' ,
376+ pageUrl : window . location . pathname ,
377+ componentName : 'ApplicationPreview' ,
378+ userAction : 'PDF_PREVIEW' ,
379+ } ) ;
380+ } }
381+ />
403382 ) : (
404383 < Text color = { colors . gray [ 400 ] } > PDF를 불러올 수 없습니다.</ Text >
405384 ) }
@@ -420,29 +399,20 @@ const Container = styled.div`
420399const ApplicationContainer = styled . div `
421400 width: 100%;
422401 background-color: ${ colors . gray [ 400 ] } ;
423- display: block;
402+ display: flex;
403+ justify-content: center;
404+ align-items: center;
424405 padding: 24px 140px;
425406 box-sizing: border-box;
426- max-height: 80vh;
427- overflow-y: auto;
407+ min-height: 80vh;
428408` ;
429409
430- const PdfViewport = styled . div `
410+ const PdfIframe = styled . iframe `
431411 width: 100%;
432- max-width: 794px;
412+ height: 80vh;
413+ border: none;
433414 background-color: ${ colors . extra . realWhite } ;
434- box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
435- display: flex;
436- flex-direction: column;
437- gap: 16px;
438- padding: 20px 0;
439- margin: 0 auto;
440- canvas {
441- max-width: 100%;
442- height: auto !important;
443- margin: 0 auto;
444- display: block;
445- }
415+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
446416` ;
447417
448418const ApplicationLoadingContainer = styled ( Skeleton ) `
0 commit comments