-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
32 lines (24 loc) · 818 Bytes
/
app.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
from docxtpl import DocxTemplate, InlineImage
import datetime as dt
import pypandoc
# Specify input and output file names
input_file = 'docs/invitation.docx'
output_file = 'docs/invitation.pdf'
# create a document object
doc = DocxTemplate("inviteTmpl.docx")
# create context dictionary
context = {
"todayStr": dt.datetime.now().strftime("%d-%b-%Y"),
"recipientName": "Chaitanya",
"evntDtStr": "21-Oct-2021",
"venueStr": "the beach",
"senderName": "Sanket",
}
# inject image into the context
context['bannerImg'] = InlineImage(doc, 'images/party_banner_0.png')
# render context into the document object
doc.render(context)
# save the document object as a word file
doc.save(input_file)
# Convert the DOCX file to PDF
output = pypandoc.convert_file(input_file, 'pdf', outputfile=output_file)