diff --git a/frontend/static/js/search.js b/frontend/static/js/search.js
index 7e2267d..faee19c 100644
--- a/frontend/static/js/search.js
+++ b/frontend/static/js/search.js
@@ -25,6 +25,9 @@ window.searchApp = function() {
previewResult: null,
previewLoading: false,
pdfError: false,
+ pdfLoading: false,
+ pdfLoaded: false,
+ pdfSrc: '',
// HTML 뷰어 상태
htmlLoading: false,
@@ -215,8 +218,8 @@ window.searchApp = function() {
// PDF가 있으면 PDF 미리보기, 없으면 HTML 미리보기
if (docInfo.pdf_path) {
- // PDF 미리보기는 iframe으로 자동 처리
- console.log('PDF 미리보기 준비 완료');
+ // PDF 미리보기 준비
+ await this.loadPdfPreview(result.document_id);
} else if (docInfo.html_path) {
// HTML 문서 미리보기
await this.loadHtmlPreview(result.document_id);
@@ -318,12 +321,55 @@ window.searchApp = function() {
this.previewLoading = false;
this.pdfError = false;
+ // PDF 리소스 정리
+ this.pdfLoading = false;
+ this.pdfLoaded = false;
+ this.pdfSrc = '';
+
// HTML 리소스 정리
this.htmlLoading = false;
this.htmlRawMode = false;
this.htmlSourceCode = '';
},
+ // PDF 미리보기 로드
+ async loadPdfPreview(documentId) {
+ this.pdfLoading = true;
+ this.pdfError = false;
+ this.pdfLoaded = false;
+
+ try {
+ // PDF 파일 존재 여부 먼저 확인
+ const response = await fetch(`/api/documents/${documentId}/pdf`, {
+ method: 'HEAD',
+ headers: {
+ 'Authorization': `Bearer ${localStorage.getItem('token')}`
+ }
+ });
+
+ if (response.ok) {
+ // PDF 파일이 존재하면 src 설정
+ const token = localStorage.getItem('token');
+ this.pdfSrc = `/api/documents/${documentId}/pdf?_token=${encodeURIComponent(token)}`;
+ console.log('PDF 미리보기 준비 완료:', this.pdfSrc);
+ } else {
+ throw new Error(`PDF 파일을 찾을 수 없습니다 (${response.status})`);
+ }
+ } catch (error) {
+ console.error('PDF 미리보기 로드 실패:', error);
+ this.pdfError = true;
+ } finally {
+ this.pdfLoading = false;
+ }
+ },
+
+ // PDF 에러 처리
+ handlePdfError() {
+ console.error('PDF iframe 로드 오류');
+ this.pdfError = true;
+ this.pdfLoading = false;
+ },
+
// HTML 미리보기 로드
async loadHtmlPreview(documentId) {
this.htmlLoading = true;