0% found this document useful (0 votes)
8 views5 pages

Generate PDF Resume with Puppeteer

The document outlines a Node.js function that generates a resume in PDF format using Puppeteer, based on user-provided data such as personal information, education, experience, skills, languages, and social profiles. It includes HTML template creation based on the selected template and handles PDF generation and response to the client. Additionally, there are React components for downloading the generated resume either as a button or a link.

Uploaded by

Nilanjana Das
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Generate PDF Resume with Puppeteer

The document outlines a Node.js function that generates a resume in PDF format using Puppeteer, based on user-provided data such as personal information, education, experience, skills, languages, and social profiles. It includes HTML template creation based on the selected template and handles PDF generation and response to the client. Additionally, there are React components for downloading the generated resume either as a button or a link.

Uploaded by

Nilanjana Das
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

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." });
}

You might also like