diff --git a/src/invoice_generator/html_generator.py b/src/invoice_generator/html_generator.py index aaaeb42..cb74880 100644 --- a/src/invoice_generator/html_generator.py +++ b/src/invoice_generator/html_generator.py @@ -13,6 +13,7 @@ class HtmlTemplate: if not Path(templates).exists(): raise FileNotFoundError(f'Inivalid path to template files: {templates}') self.templates = templates + self.path_to_template = Path(templates) def prepare_template(self, invoice_data, envelope_data): try: @@ -53,15 +54,14 @@ class HtmlTemplate: html_content = markdown.markdown(md_content) return html_content - @staticmethod - def convert_html_to_pdf(source_html, output_filename): + def convert_html_to_pdf(self, source_html, output_filename): # open output file for writing (truncated binary) result_file = open(output_filename, "w+b") # convert HTML to PDF pisa_status = pisa.CreatePDF( source_html, # the HTML to convert - path='test_data/templates/fonts', + path=str(self.path_to_template / 'fonts'), dest=result_file ) # file handle to recieve result diff --git a/src/main.py b/src/main.py index 3b985a1..a48aa5d 100644 --- a/src/main.py +++ b/src/main.py @@ -135,7 +135,7 @@ def main(): print('Generating invoice...') invoice_pdf = Path(invoice_data.Id).with_suffix('.pdf') print(f'Invoice PDF: {invoice_pdf}') - html_generator.HtmlTemplate.convert_html_to_pdf(template, invoice_pdf) + generator.convert_html_to_pdf(template, invoice_pdf) except Exception as e: print(f'Error: {e}') return