-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPdf_Generateur.py
174 lines (148 loc) · 5.85 KB
/
Pdf_Generateur.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
"""from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus import SimpleDocTemplate, Paragraph, Table, TableStyle, Image
from reportlab.lib.units import inch
from reportlab.lib import colors
def creer_bulletin_paie_pdf(fichier, nom, prenom, poste, salaire, date_paiement, signature, logo_path):
doc = SimpleDocTemplate(fichier, pagesize=letter)
styles = getSampleStyleSheet()
elements = []
#logo de l'entreprise
try:
logo = Image("logo.jpg",width=doc.width, height=1.5 * inch)
elements.append(logo)
except Exception as e:
print(f"Erreur lors du chargement du logo : {e}")
#entete
header_data = [
["GROUPE 5 PME", "01/20"],
["33 rue Pasteur", ""],
["31000 Lomé-Togo", ""]
]
header_table = Table(header_data, colWidths=[doc.width / 2.0, doc.width / 2.0])
header_table.setStyle(TableStyle([
('SPAN', (0, 0), (1, 0)),
('SPAN', (0, 1), (1, 1)),
('SPAN', (0, 2), (1, 2)),
('ALIGN', (0, 0), (1, 2), 'CENTER'),
('FONTNAME', (0, 0), (1, 2), 'Helvetica-Bold'),
('FONTSIZE', (0, 0), (1, 2), 12),
('BOTTOMPADDING', (0, 0), (1, 2), 12)
]))
elements.append(header_table)
#space html
elements.append(Paragraph("<br/><br/>", styles['Normal']))
#infos sur l'employé
employe_data = [
["Nom", "Prénom", "Poste", "Salaire Net(XOF)", "Date de Paiement"],
[nom, prenom, poste, f"{salaire}", date_paiement]
]
employe_table = Table(employe_data, colWidths=[100, 150, 100, 100, 100])
employe_table.setStyle(TableStyle([
('BACKGROUND', (0, 0), (-1, 0), colors.grey),
('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
('ALIGN', (0, 0), (-1, -1), 'CENTER'),
('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
('BOTTOMPADDING', (0, 0), (-1, 0), 12),
('BACKGROUND', (0, 1), (-1, -1), colors.beige),
('GRID', (0, 0), (-1, -1), 1, colors.black),
]))
elements.append(employe_table)
elements.append(Paragraph("<br/><br/>", styles['Normal']))
#Signature
signature_data = [
["Signature Du Directeur :", signature]
]
signature_table = Table(signature_data, colWidths=[150, 300])
signature_table.setStyle(TableStyle([
('ALIGN', (0, 0), (1, -1), 'LEFT'),
('FONTNAME', (0, 0), (1, -1), 'Helvetica'),
('FONTSIZE', (0, 0), (1, -1), 10),
('BOTTOMPADDING', (0, 0), (1, -1), 5)
]))
elements.append(signature_table)
doc.build(elements)
if __name__ == "__main__":
nom = "GANDONOU"
prenom = "Koffi Patrick-léon"
poste = "Développeur"
salaire = "500000"
date_paiement = "20/06/2023"
signature = "Signature de l'employé:"
logo_path = "logo.jpg"
creer_bulletin_paie_pdf(f"{nom}-paie.pdf", nom, prenom, poste, salaire, date_paiement, signature, logo_path)"""
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus import SimpleDocTemplate, Paragraph, Table, TableStyle, Image
from reportlab.lib.units import inch
from reportlab.lib import colors
def creer_bulletin_paie_pdf(fichier, nom, prenom, poste, salaire, date_paiement, signature):
doc = SimpleDocTemplate(fichier, pagesize=letter)
styles = getSampleStyleSheet()
elements = []
# Logo de l'entreprise
try:
logo = Image("logo.jpg", width=doc.width, height=1.5 * inch)
elements.append(logo)
except Exception as e:
print(f"Erreur lors du chargement du logo : {e}")
# En-tête
header_data = [
["GROUPE 5 PME", "01/20"],
["33 rue Pasteur", ""],
["31000 Lomé-Togo", ""]
]
header_table = Table(header_data, colWidths=[doc.width / 2.0, doc.width / 2.0])
header_table.setStyle(TableStyle([
('SPAN', (0, 0), (1, 0)),
('SPAN', (0, 1), (1, 1)),
('SPAN', (0, 2), (1, 2)),
('ALIGN', (0, 0), (1, 2), 'CENTER'),
('FONTNAME', (0, 0), (1, 2), 'Helvetica-Bold'),
('FONTSIZE', (0, 0), (1, 2), 12),
('BOTTOMPADDING', (0, 0), (1, 2), 12)
]))
elements.append(header_table)
# Espace HTML
elements.append(Paragraph("<br/><br/>", styles['Normal']))
# Infos sur l'employé
employe_data = [
["Nom", "Prénom", "Poste", "Salaire Net(XOF)", "Date de Paiement"],
[nom, prenom, poste, f"{salaire}", date_paiement]
]
employe_table = Table(employe_data, colWidths=[100, 150, 100, 100, 100])
employe_table.setStyle(TableStyle([
('BACKGROUND', (0, 0), (-1, 0), colors.grey),
('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
('ALIGN', (0, 0), (-1, -1), 'CENTER'),
('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
('BOTTOMPADDING', (0, 0), (-1, 0), 12),
('BACKGROUND', (0, 1), (-1, -1), colors.beige),
('GRID', (0, 0), (-1, -1), 1, colors.black),
]))
elements.append(employe_table)
elements.append(Paragraph("<br/><br/>", styles['Normal']))
# Signature
signature_data = [
["Signature Du DRH :", signature]
]
signature_table = Table(signature_data, colWidths=[150, 300])
signature_table.setStyle(TableStyle([
('ALIGN', (0, 0), (1, -1), 'LEFT'),
('FONTNAME', (0, 0), (1, -1), 'Helvetica'),
('FONTSIZE', (0, 0), (1, -1), 10),
('BOTTOMPADDING', (0, 0), (1, -1), 5)
]))
elements.append(signature_table)
signature_data2 = [
["Signature de l'Employé:", nom + " "+prenom]
]
signature_table = Table(signature_data2, colWidths=[150, 300])
signature_table.setStyle(TableStyle([
('ALIGN', (0, 0), (1, -1), 'LEFT'),
('FONTNAME', (0, 0), (1, -1), 'Helvetica'),
('FONTSIZE', (0, 0), (1, -1), 10),
('BOTTOMPADDING', (0, 0), (1, -1), 5)
]))
elements.append(signature_table)
doc.build(elements)