- docxtpl is a python library for populating data into word file templates.
- This helps in automating reports very easily.
- Since we are using word file templates we can use rich text features like fonts, font sizes, colors etc without any programming.
The following files are used in this blog post
- Template word files - inviteTmpl.docx, reportTmpl.docx
- images - party_banner_0.png, party_banner_1.png, party_banner_2.png
While running this scripts, create folders named images
, invites
and reports
. Download the images and move them into the images folder placed in the same folder as the script file.
If can render a variable named xyz
by writing {{ xyz }}
in the template word file. The variable can be text or image.
- This is a simple example using
docxtpl
for populating words and images into a birthday invitation template word file. - We are using the
DocxTemplate
andInlineImage
classes. - Output should be created as a files named
invitation.docx
andinvitation.pdf
. - We are using the
convert
function fromdocx2pdf
library for converting word file to pdf file.
mkvirtualenv docxtpl-env
lsvirtualenv
workon google_env
deactivate
pip install -r requirements.txt
sudo apt install texlive
sudo apt install pandoc