-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard.py
36 lines (30 loc) · 1.23 KB
/
card.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
import pdf417gen
from PIL import Image
import base64
# Sample Payload (based on your specifications)
surname = "SMITH"
given_name = "JOHN"
other_names = "wICK"
date_of_birth = "01011990"
date_of_issue = "01012020"
date_of_expiry = "01012030"
nin = "ABC123456789"
card_number = "12345678901234"
additional_data = "example_additional_data"
# Combine all the fields into a single string, separated by semicolons
payload = f"{base64.b64encode(surname.encode()).decode()};" \
f"{base64.b64encode(given_name.encode()).decode()};" \
f"{base64.b64encode(other_names.encode()).decode()};" \
f"{base64.b64encode(date_of_birth.encode()).decode()};" \
f"{base64.b64encode(date_of_issue.encode()).decode()};" \
f"{base64.b64encode(date_of_expiry.encode()).decode()};" \
f"{base64.b64encode(nin.encode()).decode()};" \
f"{base64.b64encode(card_number.encode()).decode()};" \
f"{base64.b64encode(additional_data.encode()).decode()}"
# Generate PDF417 barcode
barcode = pdf417gen.encode(payload)
# Render to an image
image = pdf417gen.render_image(barcode)
# Save the barcode image
image.save("pdf417_barcode.png")
print("✅ PDF417 barcode with all data saved as 'pdf417_barcode.png'")