Fixed utf bugs in pdf generation, deleted unnecessary files, some other minor tweaks.
This commit is contained in:
BIN
contract/out.pdf
BIN
contract/out.pdf
Binary file not shown.
@@ -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)
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user