In this part two topics will be discussed:
a. Changing HTML to PDF (After applying CSS)
b. Sending Automated Mail with GMAIL API
Doesn’t this report look a bit awkward?** Lets add some Styling**
For Table we would do “****margin:0px auto;” to center it and for divs we will give a common css to body itself :- **“text-align:center;” **and then just write the HTML again.
## Adding CSS to HTML
css = ‘<style> body {\n text-align:center; \n}\n table{\n margin:0px auto;\n}</style>’
html = html + css
with open(‘report.html’,’w+’) as file:
file.write(html)
**Converting to PDF (You need to import pdfkit library, if not installed do :- “**sudo apt-get install -y python-pdfkit” or “pip3 install pdfkit” on terminal).
Note: I am using home directory for simplicity, you can change names of directories as per your wish.
#gmail-api #python #automation #email #pdfkit