-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-pdf.py
65 lines (49 loc) · 1.45 KB
/
create-pdf.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
from PyPDF2 import PdfFileWriter, PdfFileReader
import io
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from send_email import EmailController as email_controller
def create_pdf(
amount: str,
voucher_number: str,
):
"""Create PDF
Args:
amount: amount
voucher: voucher
"""
packet = io.BytesIO()
can = canvas.Canvas(packet, pagesize=letter)
can.setFillColor("#144f5d") #
can.setFont("Helvetica-Bold", 35)
can.drawString(40, 130, amount)
can.setFillColor("#144f5d") #
can.setFont("Helvetica-Bold", 10)
can.drawString(600, 250, voucher_number)
can.setFillColor("#144f5d") #
can.setFont("Helvetica-Bold", 20)
can.drawString(300, 120, voucher_number)
can.save()
packet.seek(0)
new_pdf = PdfFileReader(packet)
# getting the existing pdf file
existing_pdf = PdfFileReader(open("assets/voucher.pdf", "rb"))
output = PdfFileWriter()
# add our text to the pdf
page = existing_pdf.getPage(0)
page.mergePage(new_pdf.getPage(0))
output.addPage(page)
# genertate a new pdf
outputStream = open("generated-pdf/" + voucher_number + ".pdf", "wb")
output.write(outputStream)
outputStream.close()
# email_controller.send_pop_as_email(transaction_reference)
amount = "$USD50"
voucher_number = "EW5144522885505575112"
# i = 0
# while i < 100:
create_pdf(
amount=amount,
voucher_number=voucher_number,
)
# i += 1