Skip to content

Commit 2753786

Browse files
committed
fix : puppeteer
1 parent e5c6666 commit 2753786

File tree

88 files changed

+1991
-77
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1991
-77
lines changed

.pnp.cjs

+850
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

packages/ui/components/PreviewResume/Project.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const Project = ({
8282
<Link
8383
key={index}
8484
href={value}
85-
className="flex items-center gap-2 bg-gray100 pl-3 pr-3 pt-2 pb-2 rounded-md w-fit max-w-full flex-1"
85+
className="flex items-center gap-2 bg-gray100 pl-2 pr-2 pt-0 pb-0 rounded-md w-fit max-w-full flex-1"
8686
>
8787
<LinkSvg />
8888
<p className="text-ellipsis overflow-hidden break-all text-[12px]">

service/admin/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"next": "13.3.0",
2828
"next-transpile-modules": "^10.0.0",
2929
"postcss": "8.4.21",
30+
"puppeteer": "^21.3.8",
3031
"qrcode.react": "^3.1.0",
3132
"react": "18.2.0",
3233
"react-dom": "18.2.0",

service/admin/src/pages/api/hello.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ export default function handler(
1010
res: NextApiResponse<Data>
1111
) {
1212
res.status(200).json({ name: 'John Doe' })
13-
}
13+
}

service/admin/src/pages/api/pdf.ts

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2+
import type { NextApiRequest, NextApiResponse } from 'next'
3+
import puppeteer from 'puppeteer';
4+
5+
export default async function handler(
6+
req: NextApiRequest,
7+
res: NextApiResponse
8+
) {
9+
try {
10+
11+
console.log("handler(")
12+
console.log(req.query.grade)
13+
14+
const browser = await puppeteer.launch({
15+
headless: "new",
16+
args: [
17+
'--window-size=1164,829',
18+
'--disable-dev-shm-usage',
19+
'--no-sandbox',
20+
'--disable-setuid-sandbox'
21+
]
22+
});
23+
24+
const page = await browser.newPage();
25+
await page.setViewport({
26+
width: 829,
27+
height: 1164
28+
});
29+
console.log("829")
30+
31+
const timeout = 60 * 1000;
32+
const url: string = 'http://localhost:3000/render-pdf/' + req.query.grade
33+
const navigationPromise = await page.goto(url, {
34+
waitUntil: 'networkidle0',
35+
timeout: timeout // Set the navigation timeout
36+
});
37+
// Wait for navigation to complete or timeout
38+
await Promise.race([navigationPromise, page.waitForTimeout(timeout)]);
39+
40+
const buffer = await page.pdf({
41+
path: 'example.pdf',
42+
format: 'A4',
43+
printBackground: true,
44+
margin: { top: 5, right: 0, bottom: 5, left: 0 },
45+
scale: 1.4
46+
});
47+
48+
await browser.close();
49+
res.send(buffer);
50+
} catch (error) {
51+
console.error('An error occurred:', error);
52+
res.status(500).send('An error occurred');
53+
}
54+
}
55+
56+
export const config = {
57+
api: {
58+
responseLimit: false,
59+
},
60+
}

service/admin/src/pages/pdf/convert2PDFAll.ts

+8-65
Original file line numberDiff line numberDiff line change
@@ -7,72 +7,15 @@ export const convert2PdfAll = async (
77
fileName: string
88
) => {
99
if (!current) return;
10-
const promise = async () => {
11-
console.time("make data");
12-
const maxPage = 18;
13-
const loopNum = Math.ceil(current.scrollHeight / (1164 * maxPage));
14-
const canvas = [];
1510

16-
let offset = 0;
17-
for (let i = 0; i < loopNum; i++) {
18-
canvas.push(
19-
await html2canvas(current, {
20-
height:
21-
i === loopNum - 1
22-
? current.scrollHeight - (loopNum - 1) * maxPage * 1164
23-
: 1164 * maxPage,
24-
y: offset,
25-
scale: 1,
26-
backgroundColor: "#f6f6f6",
27-
})
28-
);
29-
offset += 1164 * maxPage;
30-
console.log(offset);
31-
}
11+
console.log("sdfs")
12+
const response = await fetch(`/api/pdf?grade=2`);
13+
const blob = await response.blob();
3214

33-
console.log(canvas);
15+
// Create a URL for the blob
16+
const pdfUrl = URL.createObjectURL(blob);
17+
console.log(pdfUrl)
3418

35-
const imgData = canvas.map((value) => value.toDataURL("image/png"));
36-
37-
const imgWidth = 210;
38-
const pageHeight = 295;
39-
40-
const doc = new jsPDF("p", "mm", "a4", true);
41-
42-
console.timeEnd("make data");
43-
44-
canvas.map((canvas, index) => {
45-
const imgHeight = (canvas.height * imgWidth) / canvas.width;
46-
let heightLeft = imgHeight;
47-
let position = 0;
48-
let asdf = 0;
49-
50-
while (heightLeft >= 0) {
51-
asdf += 1;
52-
doc.addImage(
53-
imgData[index],
54-
"PNG",
55-
0,
56-
position,
57-
imgWidth,
58-
imgHeight,
59-
undefined,
60-
"FAST"
61-
);
62-
heightLeft -= pageHeight;
63-
position = heightLeft - imgHeight;
64-
console.log("add page " + asdf);
65-
if (heightLeft < 0 && index + 1 === imgData.length) return;
66-
doc.addPage();
67-
}
68-
});
69-
doc.save(fileName + ".pdf");
70-
};
71-
promise()
72-
.then(() => {
73-
console.log("success");
74-
})
75-
.catch((e) => {
76-
console.log(e);
77-
});
19+
// Open the PDF in a new tab for preview
20+
window.open(pdfUrl, '_blank');
7821
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
import { Tag } from "@packages/ui/components/PreviewResume/Tag";
2+
import { Award } from "@packages/ui/components/PreviewResume/Award";
3+
import { Certificate } from "@packages/ui/components/PreviewResume/Certificate";
4+
import { Project } from "@packages/ui/components/PreviewResume/Project";
5+
import {
6+
Dispatch,
7+
SetStateAction,
8+
useEffect,
9+
useLayoutEffect,
10+
useRef,
11+
useState,
12+
} from "react";
13+
import { Activity } from "@packages/ui/components/PreviewResume/Activity";
14+
import QRCode from "qrcode.react";
15+
import { PreviewType } from "@packages/ui/components/PreviewResume/PreviewType";
16+
import { studentIndex } from ".";
17+
18+
const subject = {
19+
1: "소프트웨어개발과",
20+
2: "소프트웨어개발과",
21+
3: "임베디드소프트웨어과",
22+
4: "정보보안과",
23+
};
24+
25+
interface indexType {
26+
data: PreviewType;
27+
setIndex: Dispatch<SetStateAction<{ [k: string]: studentIndex }>>;
28+
}
29+
30+
const DetailPage = ({ data, setIndex }: indexType) => {
31+
const {
32+
writer,
33+
introduce,
34+
skill_list,
35+
project_list,
36+
award_list,
37+
certificate_list,
38+
activity_list,
39+
} = data;
40+
41+
const [grade, classNum] = writer.student_number.toString().split("");
42+
const [page, setPage] = useState<number>(1);
43+
const [trigger, setTrigger] = useState<boolean>(false);
44+
45+
const activity = useRef<HTMLElement>(null);
46+
const one = useRef<HTMLDivElement>(null);
47+
48+
const heightCheck = () => {
49+
if (one.current && one.current?.scrollHeight > 1264) {
50+
setPage(2);
51+
console.log("page set 2: " + one.current?.scrollHeight);
52+
} else {
53+
setPage(1);
54+
}
55+
};
56+
57+
useLayoutEffect(() => {
58+
setTimeout(() => {
59+
heightCheck();
60+
}, 100);
61+
}, [trigger]);
62+
useEffect(() => {
63+
setTimeout(() => {
64+
setTrigger(true);
65+
}, 1000);
66+
}, []);
67+
useEffect(() => {
68+
setIndex((i) => {
69+
return {
70+
...i,
71+
[writer.student_number]: {
72+
name: writer.name,
73+
major: writer.major,
74+
studentNumber: writer.student_number,
75+
page: page + project_list.length,
76+
},
77+
};
78+
});
79+
}, [page]);
80+
81+
const ActivityList = (
82+
<>
83+
{activity_list.length > 0 && (
84+
<article className="flex gap-[10px] flex-col" ref={activity}>
85+
<h3 className="text-body5">활동</h3>
86+
{activity_list.map((data, index) => (
87+
<Activity {...data} key={index} />
88+
))}
89+
</article>
90+
)}
91+
</>
92+
);
93+
return (
94+
<>
95+
<page>
96+
<div className="w-[831px] h-[1171px] bg-gray50 flex justify-center items-center">
97+
<div
98+
className="h-full w-full flex flex-col gap-[20px] scale-[0.92]"
99+
ref={one}
100+
>
101+
<article>
102+
<div className="flex justify-between items-center">
103+
<div>
104+
<p className="text-title1 mb-[10px]">{writer.name}</p>
105+
<p className="text-title4">{writer.major.name}</p>
106+
</div>
107+
<div className="flex">
108+
<div className="flex flex-col mr-6 text-end gap-[10px] justify-center">
109+
<p className="text-body7 leading-[17px]">
110+
{writer.student_number}
111+
</p>
112+
<p className="text-body7 leading-[17px]">
113+
{grade !== "1" ? subject[classNum as "1"] : "공통과정"}
114+
</p>
115+
<p className="text-body7 leading-[17px]">{writer.email}</p>
116+
</div>
117+
{writer.url && (
118+
<div>
119+
<QRCode size={80} value={writer.url} />
120+
</div>
121+
)}
122+
</div>
123+
</div>
124+
</article>
125+
126+
<article>
127+
<div>
128+
<h3 className="text-body3">{introduce.heading}</h3>
129+
<pre className="text-body7 whitespace-pre-wrap text-gray400 mt-[20px] leading-[17px]">
130+
{introduce.introduce}
131+
</pre>
132+
</div>
133+
</article>
134+
135+
{!!skill_list.length && (
136+
<article className="flex flex-col gap-[10px]">
137+
<h3 className="text-body5">기술 스택</h3>
138+
<pre className="flex gap-3 flex-wrap">
139+
{skill_list.map((skill, index) => (
140+
<Tag key={index} className="bg-gray50" technology={skill} />
141+
))}
142+
</pre>
143+
</article>
144+
)}
145+
146+
{award_list.length > 0 && (
147+
<article className="flex gap-[10px] flex-col">
148+
<h3 className="text-body5">수상 경력</h3>
149+
{award_list.map((award, index) => (
150+
<Award {...award} key={index} />
151+
))}
152+
</article>
153+
)}
154+
155+
{certificate_list.length > 0 && (
156+
<article className="flex gap-[10px] flex-col">
157+
<h3 className="text-body5">자격증</h3>
158+
{certificate_list.map((data, index) => (
159+
<Certificate {...data} key={index} />
160+
))}
161+
</article>
162+
)}
163+
{page === 1 && ActivityList}
164+
</div>
165+
</div>
166+
</page>
167+
168+
{page > 1 && (
169+
<page>
170+
<div className="w-[831px] h-[1171px] flex justify-center items-center">
171+
<div className="h-full w-full flex scale-[0.92]">
172+
<div className="h-fit w-full flex flex-col gap-[20px]" id="two">
173+
{page === 2 && ActivityList}
174+
</div>
175+
</div>
176+
</div>
177+
</page>
178+
)}
179+
<article className="flex flex-col">
180+
{project_list.map((data, index) => (
181+
<div
182+
className="w-[831px] h-[1171px] bg-gray50 flex flex-col justify-center items-center"
183+
key={index}
184+
>
185+
<div className="w-[831px] h-[1171px] flex flex-col gap-[20px] scale-[0.92]">
186+
{/* {index === 0 && (
187+
<h3 className="text-[22px] font-semibold leading-[26px] w-full">
188+
Project
189+
</h3>
190+
)} */}
191+
<page>
192+
<div className={`h-full w-full`}>
193+
<Project {...data} />
194+
</div>
195+
</page>
196+
</div>
197+
</div>
198+
))}
199+
</article>
200+
</>
201+
);
202+
};
203+
204+
export default DetailPage;

0 commit comments

Comments
 (0)