diff options
Diffstat (limited to 'dealconvert/formats')
-rw-r--r-- | dealconvert/formats/html.py | 2 | ||||
-rw-r--r-- | dealconvert/formats/pdf.py | 40 |
2 files changed, 41 insertions, 1 deletions
diff --git a/dealconvert/formats/html.py b/dealconvert/formats/html.py index 244b6f2..0b5b403 100644 --- a/dealconvert/formats/html.py +++ b/dealconvert/formats/html.py @@ -188,7 +188,7 @@ class HTMLFormat(DealFormat): for row in deal_rows: table_content += '<table style="margin-top: -1px"><tr>' for deal in row: - table_content += '<td style="width: 4.9cm; border: solid 1px black">' + table_content += '<td style="width: 6.4cm; border: solid 1px black; padding: 0">' deal_cells = [ ['', '', '', ''], ['', '', '', ''], diff --git a/dealconvert/formats/pdf.py b/dealconvert/formats/pdf.py new file mode 100644 index 0000000..9a4f6ca --- /dev/null +++ b/dealconvert/formats/pdf.py @@ -0,0 +1,40 @@ +import tempfile +import warnings + +import pdfkit + +from . import DealFormat +from .html import HTMLFormat +from .. import dto + + +class PDFFormat(DealFormat): + @property + def suffix(self): + return '.pdf' + + def __init__(self, *args, **kwargs): + DealFormat.__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() |