const puppeteer = require("puppeteer");
[Link] = async (req, res) => {
const {
basicInfoData,
eduData,
expData,
summaryText,
skills,
selectedTemplate,
language,
socials,
} = [Link];
const { imgUrl } = basicInfoData; // Extract imgUrl from basicInfoData
let htmlTemplate = "";
if (selectedTemplate === 1) {
htmlTemplate = `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
font-family: Arial, sans-serif;
padding: 40px;
line-height: 1.6;
color: #333;
}
.header {
display: flex;
align-items: center;
margin-bottom: 30px;
}
.profile-pic {
width: 120px;
height: 120px;
border-radius: 50%;
object-fit: cover;
margin-right: 25px;
border: 2px solid #888;
}
.info h1 {
margin: 0;
font-size: 28px;
}
.info h2 {
margin: 5px 0;
font-weight: normal;
font-size: 20px;
}
.info h5 {
margin: 3px 0;
font-weight: normal;
color: #555;
}
.section {
margin-top: 25px;
}
.section h2 {
font-size: 20px;
border-bottom: 1px solid #aaa;
padding-bottom: 5px;
}
.entry {
margin-bottom: 10px;
}
ul {
padding-left: 20px;
}
a {
color: #1a0dab;
text-decoration: none;
}
</style>
</head>
<body>
<div class="header">
${imgUrl ? `<img src="${imgUrl}" class="profile-pic" alt="Profile
Picture">` : ""}
<div class="info">
<h1>${[Link]} ${[Link]}</h1>
<h2>${[Link]}</h2>
<h5>${[Link]} | ${[Link]}</h5>
<h5>${[Link]}, ${[Link]}</h5>
</div>
</div>
<div class="section">
<h2>Summary</h2>
<p>${summaryText}</p>
</div>
<div class="section">
<h2>Experience</h2>
${[Link](exp => `
<div class="entry">
<strong>${[Link]}</strong><br/>
${[Link]}, ${[Link]}<br/>
${[Link]} - ${[Link]}<br/>
<p>${[Link]}</p>
</div>
`).join("")}
</div>
<div class="section">
<h2>Education</h2>
${[Link](edu => `
<div class="entry">
<strong>${[Link]}</strong><br/>
${[Link]}, ${[Link]}<br/>
${[Link]} - ${[Link]}<br/>
<p>${[Link]}</p>
</div>
`).join("")}
</div>
<div class="section">
<h2>Skills</h2>
<ul>
${[Link](skill => `<li>${[Link]} -
${[Link]}/5</li>`).join("")}
</ul>
</div>
<div class="section">
<h2>Languages</h2>
<ul>
${[Link](lang => `<li>${[Link]} -
${[Link]}/5</li>`).join("")}
</ul>
</div>
<div class="section">
<h2>Social Profiles</h2>
<ul>
${[Link](social => `<li>${[Link]}: <a href="${[Link]}"
target="_blank">${[Link]}</a></li>`).join("")}
</ul>
</div>
</body>
</html>
`;
}
try {
const browser = await [Link]({
headless: "new", // For compatibility with recent Puppeteer versions
args: ["--no-sandbox", "--disable-setuid-sandbox"],
});
const page = await [Link]();
await [Link](htmlTemplate, { waitUntil: "networkidle0" });
const pdfBuffer = await [Link]({
format: "A4",
printBackground: true,
});
await [Link]();
[Link]({
"Content-Type": "application/pdf",
"Content-Length": [Link],
});
return [Link](pdfBuffer);
} catch (err) {
[Link]("PDF Generation Error:", err);
return [Link](500).json({ error: "Failed to generate resume." });
}
};
// [Link]
import React from 'react';
const ResumeDownloadButton = ({ resumeData }) => {
const handleDownload = async () => {
try {
const response = await fetch('[Link] {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: [Link](resumeData),
});
if (![Link]) {
throw new Error('Failed to generate resume');
}
const blob = await [Link]();
const url = [Link](blob);
const a = [Link]('a');
[Link] = url;
[Link] = '[Link]';
[Link]();
[Link](url); // Clean up
} catch (error) {
[Link]('Download failed:', error);
}
};
return <button onClick={handleDownload}>Download Resume</button>;
};
export default ResumeDownloadButton;
// [Link]
import React from 'react';
const ResumeDownloadLink = () => {
const handleDownload = () => {
[Link]('[Link] '_blank');
};
return <button onClick={handleDownload}>Download Resume</button>;
};
export default ResumeDownloadLink;
const fs = require("fs");
const path = require("path");
try {
const browser = await [Link]({
headless: "new",
args: ["--no-sandbox", "--disable-setuid-sandbox"],
});
const page = await [Link]();
await [Link](htmlTemplate, { waitUntil: "networkidle0" });
// Save PDF to disk
const filePath = [Link](__dirname, "[Link]");
await [Link]({
path: filePath,
format: "A4",
printBackground: true,
});
await [Link]();
// Also read PDF as buffer to send to frontend
const pdfBuffer = [Link](filePath);
[Link]({
"Content-Type": "application/pdf",
"Content-Length": [Link],
});
return [Link](pdfBuffer);
} catch (err) {
[Link]("PDF Generation Error:", err);
return [Link](500).json({ error: "Failed to generate resume." });
}