-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrender.py
54 lines (45 loc) · 1.9 KB
/
render.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
from docxtpl import DocxTemplate
import pandas as pd
import numpy as np
from docx2pdf import convert
class Visitor:
def __init__(self, name, unit, accompanying_adult, children_1, children_2, children_3, contact_number):
self.name = name
self.unit = unit
self.accompanying_adult = accompanying_adult
self.children_1 = children_1
self.children_2 = children_2
self.children_3 = children_3
self.contact_number = contact_number
def create_tags(visitors):
for visitor in visitors:
doc = DocxTemplate("template.docx")
context = {
'name': visitor.name,
'unit': visitor.unit,
'accompanying_adult': visitor.accompanying_adult,
'children_1': visitor.children_1,
'children_2': visitor.children_2,
'children_3': visitor.children_3,
'contact_number': visitor.contact_number
}
doc.render(context)
# doc.save(f"{visitor.name[:5]}.docx")
doc.save('C:\CGI_projects\identity_card_design\\badges_in_word_format\\' +
f"{visitor.name[:5]}.docx")
convert('C:\CGI_projects\identity_card_design\\badges_in_word_format\\' +
f"{visitor.name[:5]}.docx", 'C:\CGI_projects\identity_card_design\\badges_in_pdf_format\\' + f"{visitor.name[:5]}.pdf")
#convert(f"{visitor.name[:5]}.docx", f"{visitor.name[:5]}.pdf")
visitor_data = pd.read_excel('data_ids.xlsx', index_col=0)
visitor_data = visitor_data.replace(np.nan, '-', regex=True)
# print(visitor_data['name'])
for index, row in visitor_data.iterrows():
visitor_data = [row.name,
row.unit,
row.accompanying_adult,
row.children_1,
row.children_2,
row.children_3,
row.contact_number]
visitors = [Visitor(*visitor_data)]
create_tags(visitors)