-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudentID.py
72 lines (57 loc) · 1.77 KB
/
StudentID.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
"""
Rozmiar ID-1: 85.60 mm × 53.98 mm
3.370" × 2.125"
1011 x 637,5 px (@300 dpi)
2022 x 1275 px (@600 dpi)
"""
from fpdf import FPDF
from pdf2image import convert_from_path
import os
class StudentID:
def __init__(self):
pass
@staticmethod
def generate(name, birthdate, pesel, school, principal, issueDate, idNumber, photo, fileName, background = False):
pdf = FPDF()
pdf.add_font(fname='/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf')
pdf.set_font('DejaVuSans-Bold', size=6)
if background:
pdf.set_page_background('legitymacja300.png')
pdf.add_page(format=(85.6, 53.98))
pdf.set_margin(0)
pdf.set_xy(27, 17)
pdf.cell(None, None, name)
pdf.set_xy(27, 23)
pdf.cell(None, None, birthdate)
pdf.set_xy(54.5, 23)
pdf.cell(None, None, pesel)
sn = school.splitlines()
flp = 29.0
nlp = 2.4
for line in sn:
pdf.set_xy(27, flp)
pdf.cell(None, None, line)
flp += nlp
pdf.set_xy(27, 41)
pdf.cell(None, None, principal)
pdf.set_xy(27, 47)
pdf.cell(None, None, issueDate)
pdf.set_font('DejaVuSans-Bold', size=8)
pdf.set_xy(9, 47.4)
pdf.cell(None, None, idNumber)
pdf.image(photo, 5.5, 17, 19, 26)
pdf.output(fileName)
@staticmethod
def generateView(name, birthdate, pesel, school, principal, issueDate, idNumber, photo, tempdir):
fileName = tempdir + "/view.pdf"
#print(fileName)
fileNamePng = tempdir + "/view.png"
StudentID.generate(name, birthdate, pesel, school, principal, issueDate, idNumber, photo, fileName, True)
if os.path.exists(fileName):
convert_from_path(fileName, dpi=96, output_folder=tempdir, fmt="png", single_file=True, output_file="view")
if os.path.exists(fileNamePng):
f = open(fileNamePng, "rb")
d = f.read()
f.close()
return d
return None