"""Exports ATS-friendly : une colonne, pas de tableaux, titres standards, polices standards.""" from docx import Document from docx.shared import Pt, Cm from reportlab.lib.pagesizes import A4 from reportlab.lib.styles import ParagraphStyle from reportlab.lib.units import cm from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, ListFlowable, ListItem from xml.sax.saxutils import escape def to_docx(r, path): d = Document() for s in d.sections: s.left_margin = s.right_margin = Cm(1.8); s.top_margin = s.bottom_margin = Cm(1.5) st = d.styles["Normal"]; st.font.name = "Calibri"; st.font.size = Pt(10.5) def h(t): p = d.add_paragraph(); run = p.add_run(t); run.bold = True; run.font.size = Pt(12); p.paragraph_format.space_before = Pt(8) p = d.add_paragraph(); x = p.add_run(r["name"]); x.bold = True; x.font.size = Pt(18) p = d.add_paragraph(); x = p.add_run(r["title"]); x.bold = True; x.font.size = Pt(12) d.add_paragraph(f'{r["contact"]} | {r["avail"]}') h(r["L"]["profile"]); d.add_paragraph(r["summary"]) h(r["L"]["exp"]) for e in r["experiences"]: p = d.add_paragraph(); a = p.add_run(f'{e["title"]} — {e["company"]}, {e["loc"]}'); a.bold = True d.add_paragraph(e["period"]).runs[0].italic = True for b in e["bullets"]: d.add_paragraph(b, style="List Bullet") h(r["L"]["skills"]); d.add_paragraph(" | ".join(r["skills"])) h(r["L"]["edu"]) for e in r["education"]: d.add_paragraph(f'{e["deg"]} — {e["school"]} ({e["years"]})') if r["certs"]: h(r["L"]["cert"]) for c in r["certs"]: d.add_paragraph(c, style="List Bullet") h(r["L"]["lang"]) for x in r["languages"]: d.add_paragraph(x, style="List Bullet") d.save(path) def to_pdf(r, path): base = ParagraphStyle("b", fontName="Helvetica", fontSize=9.5, leading=12.5) H = ParagraphStyle("h", parent=base, fontName="Helvetica-Bold", fontSize=11, spaceBefore=8, spaceAfter=3) B = ParagraphStyle("t", parent=base, fontName="Helvetica-Bold") P = lambda t, s=base: Paragraph(escape(t), s) f = [Paragraph(escape(r["name"]), ParagraphStyle("n", parent=base, fontName="Helvetica-Bold", fontSize=18, leading=22)), P(r["title"], ParagraphStyle("tt", parent=B, fontSize=11.5, leading=15)), P(f'{r["contact"]} | {r["avail"]}'), P(r["L"]["profile"], H), P(r["summary"]), P(r["L"]["exp"], H)] for e in r["experiences"]: f += [Spacer(1, 3), P(f'{e["title"]} — {e["company"]}, {e["loc"]}', B), P(e["period"], ParagraphStyle("i", parent=base, fontName="Helvetica-Oblique")), ListFlowable([ListItem(P(b), leftIndent=10) for b in e["bullets"]], bulletType="bullet", start="•", leftIndent=10)] f += [P(r["L"]["skills"], H), P(" | ".join(r["skills"])), P(r["L"]["edu"], H)] + [P(f'{e["deg"]} — {e["school"]} ({e["years"]})') for e in r["education"]] if r["certs"]: f += [P(r["L"]["cert"], H), ListFlowable([ListItem(P(c), leftIndent=10) for c in r["certs"]], bulletType="bullet", start="•", leftIndent=10)] f += [P(r["L"]["lang"], H)] + [P(x) for x in r["languages"]] SimpleDocTemplate(path, pagesize=A4, leftMargin=1.8*cm, rightMargin=1.8*cm, topMargin=1.5*cm, bottomMargin=1.5*cm).build(f)