from docx import Document
from docx.shared import Pt
from fpdf import FPDF
# ---------------------------
# 1. Format Resume into Word
# ---------------------------
def create_word_resume(data, filename="resume.docx"):
doc = Document()
# Title (Name)
title = doc.add_paragraph(data["name"])
title.style = doc.styles['Title']
# Contact Info
doc.add_paragraph(f'Email: {data["email"]} | Phone: {data["phone"]}')
# Sections
doc.add_heading('Summary', level=1)
doc.add_paragraph(data["summary"])
doc.add_heading('Experience', level=1)
for job in data["experience"]:
doc.add_paragraph(f"{job['role']} at {job['company']} ({job['years']})")
doc.add_paragraph(job["details"], style="List Bullet")
doc.add_heading('Education', level=1)
for edu in data["education"]:
doc.add_paragraph(f"{edu['degree']} - {edu['institution']} ({edu['year']})")
doc.add_heading('Skills', level=1)
doc.add_paragraph(", ".join(data["skills"]))
doc.save(filename)
print(f"✅ Word Resume saved as {filename}")
# ---------------------------
# 2. Format Resume into PDF
# ---------------------------
def create_pdf_resume(data, filename="resume.pdf"):
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", 'B', 16)
# Title (Name)
pdf.cell(200, 10, data["name"], ln=True, align="C")
pdf.set_font("Arial", '', 12)
pdf.cell(200, 10, f'Email: {data["email"]} | Phone: {data["phone"]}', ln=True, align="C")
# Sections
pdf.set_font("Arial", 'B', 14)
pdf.cell(200, 10, "Summary", ln=True)
pdf.set_font("Arial", '', 12)
pdf.multi_cell(0, 10, data["summary"])
pdf.set_font("Arial", 'B', 14)
pdf.cell(200, 10, "Experience", ln=True)
pdf.set_font("Arial", '', 12)
for job in data["experience"]:
pdf.multi_cell(0, 10, f"{job['role']} at {job['company']} ({job['years']})\n - {job['details']}")
pdf.set_font("Arial", 'B', 14)
pdf.cell(200, 10, "Education", ln=True)
pdf.set_font("Arial", '', 12)
for edu in data["education"]:
pdf.cell(200, 10, f"{edu['degree']} - {edu['institution']} ({edu['year']})", ln=True)
pdf.set_font("Arial", 'B', 14)
pdf.cell(200, 10, "Skills", ln=True)
pdf.set_font("Arial", '', 12)
pdf.multi_cell(0, 10, ", ".join(data["skills"]))
pdf.output(filename)
print(f"✅ PDF Resume saved as {filename}")
# ---------------------------
# Example Data
# ---------------------------
resume_data = {
"name": "John Doe",
"email": "john.doe@email.com",
"phone": "+1-234-567-890",
"summary": "Passionate software engineer with 5+ years of experience in building scalable applications.",
"experience": [
{"role": "Backend Developer", "company": "TechCorp", "years": "2020-2023", "details": "Developed APIs and microservices using Python & Django."},
{"role": "Software Engineer", "company": "CodeWorks", "years": "2017-2020", "details": "Worked on automation tools and optimized system performance."}
],
"education": [
{"degree": "B.Sc. Computer Science", "institution": "XYZ University", "year": "2017"}
],
"skills": ["Python", "Django", "Flask", "SQL", "Docker", "AWS"]
}
# Run both functions
create_word_resume(resume_data)
create_pdf_resume(resume_data)
No comments:
Post a Comment