blob: de3e880810dd2d4d3a4f50946d30ac4d7746d5eb (
plain)
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
|
import sys
import logging
import pdfkit
def generate(html):
logging.info("PDF generation...")
pdf_output_path = "out/out.pdf"
import os
if not os.path.exists("out"):
os.makedirs("out", exist_ok=True)
try:
config = pdfkit.configuration(wkhtmltopdf='/usr/bin/wkhtmltopdf')
options = {
'quiet': '',
'page-size': 'A4',
'margin-top': '0in',
'margin-right': '0in',
'margin-bottom': '0in',
'margin-left': '0in',
'encoding': "UTF-8",
}
pdfkit.from_string(
html,
pdf_output_path,
configuration=config,
options=options)
except (IOError, OSError) as e:
logging.exception("Something append: {}".format(e))
else:
logging.info("PDF generated at {}".format(pdf_output_path))
|