Fixed utf bugs in pdf generation, deleted unnecessary files, some other minor tweaks.

This commit is contained in:
mihasinkec
2021-02-21 15:16:40 +01:00
parent c1d6cbbb70
commit fd4bad4afe
7 changed files with 19 additions and 52 deletions

Binary file not shown.

View File

@@ -1,43 +0,0 @@
import pdfkit
from jinja2 import Environment, FileSystemLoader
class ContractCreator:
def __init__(self):
template_loader = FileSystemLoader(searchpath="./")
template_env = Environment(loader=template_loader)
self.template = template_env.get_template('template.html')
self.pdfkit_options = {
'page-size': 'A4',
'margin-top': '0.75in',
'margin-right': '0.75in',
'margin-bottom': '0.75in',
'margin-left': '0.75in',
'encoding': "UTF-8",
'custom-header' : [
('Accept-Encoding', 'gzip')
]
}
def fill_template(self, **kwargs):
return self.template.render(**kwargs)
def create_pdf(self, out_f, fields_dict):
html_str = self.fill_template(**fields_dict)
pdfkit.from_string(html_str, out_f, options=self.pdfkit_options)
if __name__ == '__main__':
test_data = {
'ime_priimek': 'Testko Tester',
'naslov': 'Testovci 10',
'posta': '1123',
'kontakt_narocnik': 'Testica Testkovič',
'kontakt_imetnikpravic': 'Testko Tester',
'date': '16.2.2021'
}
contract_creator = ContractCreator()
contract_creator.create_pdf('out.pdf', test_data)

View File

@@ -1,6 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
table, th, td {
border: 1px solid black;