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
|
import tempfile
import warnings
import pdfkit
from . import BinaryFormat
from .html import HTMLFormat
from .. import dto
class PDFFormat(BinaryFormat):
@property
def suffix(self):
return '.pdf'
def __init__(self, *args, **kwargs):
BinaryFormat.__init__(self, *args, **kwargs)
self.html_formatter = HTMLFormat(*args, **kwargs)
def parse_content(self, content):
raise NotImplementedError
def output_content(self, out_file, dealset):
html_content = self.html_formatter.get_html_content(dealset)
temp_file = tempfile.NamedTemporaryFile(delete=True)
pdfkit.from_string(html_content, temp_file.name, options={
'quiet': '',
'margin-bottom': '0',
'margin-top': '0.35cm',
'margin-left': '0',
'margin-right': '0',
'print-media-type': '',
'page-size': 'A4',
'header-left': ' ' + dealset[0].event,
'header-right': 'Page [page] ',
'header-font-size': '8',
'orientation': self.options.get('orientation', 'Landscape') or 'Landscape'
})
out_file.write(temp_file.read())
temp_file.close()
|