pdf 라이브러리 삭제
This commit is contained in:
@@ -44,7 +44,6 @@
|
|||||||
"google-libphonenumber": "^3.2.34",
|
"google-libphonenumber": "^3.2.34",
|
||||||
"ilib": "^14.3.0",
|
"ilib": "^14.3.0",
|
||||||
"patch-package": "^8.0.0",
|
"patch-package": "^8.0.0",
|
||||||
"pdfjs-dist": "^5.3.31",
|
|
||||||
"postinstall-postinstall": "^2.1.0",
|
"postinstall-postinstall": "^2.1.0",
|
||||||
"prop-types": "^15.6.2",
|
"prop-types": "^15.6.2",
|
||||||
"raw-loader": "^4.0.2",
|
"raw-loader": "^4.0.2",
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
||||||
import * as pdfjsLib from "pdfjs-dist";
|
|
||||||
import pdfjsWorker from "pdfjs-dist/build/pdf.worker.mjs.map";
|
|
||||||
import { getDocument } from "pdfjs-dist";
|
|
||||||
|
|
||||||
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsWorker;
|
|
||||||
|
|
||||||
const PDFViewer = ({ pdfPath }) => {
|
|
||||||
const canvasRef = useRef(null);
|
|
||||||
const [page, setPage] = useState(1);
|
|
||||||
|
|
||||||
const drawCanvas = useCallback(
|
|
||||||
({ width, height }) => {
|
|
||||||
if (!canvasRef.current) {
|
|
||||||
throw new Error("canvasRef가 없음");
|
|
||||||
}
|
|
||||||
const canvas = canvasRef.current;
|
|
||||||
canvas.width = width;
|
|
||||||
canvas.height = height;
|
|
||||||
|
|
||||||
const context = canvas.getContext("2d");
|
|
||||||
if (context) {
|
|
||||||
return context;
|
|
||||||
} else {
|
|
||||||
throw new Error("canvas context가 없음");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[canvasRef]
|
|
||||||
);
|
|
||||||
|
|
||||||
const renderPage = useCallback(
|
|
||||||
async (doc) => {
|
|
||||||
const currentPage = await doc.getPage(page);
|
|
||||||
const viewport = currentPage.getViewport({ scale: 1.0 }); // each pdf has its own viewport
|
|
||||||
const context = drawCanvas({
|
|
||||||
width: viewport.width,
|
|
||||||
height: viewport.height,
|
|
||||||
});
|
|
||||||
|
|
||||||
const renderContext = {
|
|
||||||
canvasContext: context,
|
|
||||||
viewport: viewport,
|
|
||||||
};
|
|
||||||
|
|
||||||
await currentPage.render(renderContext).promise;
|
|
||||||
console.log(`${page}로딩 성공`);
|
|
||||||
},
|
|
||||||
[page, drawCanvas]
|
|
||||||
);
|
|
||||||
|
|
||||||
const getPDF = useCallback(
|
|
||||||
async (pdfPath) => {
|
|
||||||
try {
|
|
||||||
const loadingTask = getDocument(pdfPath);
|
|
||||||
const doc = await loadingTask.promise;
|
|
||||||
|
|
||||||
const pageNum = doc.numPages;
|
|
||||||
console.log(`document 로딩 성공: 전체 페이지 ${pageNum}`);
|
|
||||||
|
|
||||||
renderPage(doc);
|
|
||||||
console.log("pdf 로딩 성공이라네");
|
|
||||||
} catch (e) {
|
|
||||||
console.log("pdf 로딩 실패!");
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[renderPage]
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getPDF(pdfPath);
|
|
||||||
}, [pdfPath]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<canvas ref={canvasRef} style={{ height: "500px" }} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default PDFViewer;
|
|
||||||
@@ -86,8 +86,6 @@ import OptionalTermsConfirm from "../../components/Optional/OptionalTermsConfirm
|
|||||||
import OptionalTermsConfirmBottom from "../../components/Optional/OptionalTermsConfirmBottom";
|
import OptionalTermsConfirmBottom from "../../components/Optional/OptionalTermsConfirmBottom";
|
||||||
import css from "./MainView.module.less";
|
import css from "./MainView.module.less";
|
||||||
|
|
||||||
import PDFViewer from "../../components/PDFViewer/PDFViewer";
|
|
||||||
|
|
||||||
const preloadImages = [
|
const preloadImages = [
|
||||||
LoadingPreloadImage,
|
LoadingPreloadImage,
|
||||||
LoadingAnimation,
|
LoadingAnimation,
|
||||||
@@ -839,21 +837,6 @@ export default function MainView({ className, initService }) {
|
|||||||
onClick={handleAgree}
|
onClick={handleAgree}
|
||||||
/>
|
/>
|
||||||
)} */}
|
)} */}
|
||||||
{/* <button
|
|
||||||
style={{
|
|
||||||
position: "fixed",
|
|
||||||
left: "0",
|
|
||||||
bottom: "0",
|
|
||||||
color: "#fff",
|
|
||||||
fontSize: "13px",
|
|
||||||
opacity: ".5",
|
|
||||||
zIndex: "999",
|
|
||||||
}}
|
|
||||||
onClick={() => setShowPDF(true)}
|
|
||||||
>
|
|
||||||
button
|
|
||||||
</button>
|
|
||||||
{showPDF && <PDFViewer pdfPath={"https://www.orimi.com/pdf-test.pdf"} />} */}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user