diff --git a/frappe/__init__.py b/frappe/__init__.py index e887763463..98582c76de 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -2082,7 +2082,7 @@ def get_print( password=None, pdf_options=None, letterhead=None, - chrome_pdf_generator=None, + pdf_generator: Literal["wkhtmltopdf", "chrome"] | None = None, ): """Get Print Format for given document. @@ -2091,21 +2091,23 @@ def get_print( :param print_format: Print Format name. Default 'Standard', :param style: Print Format style. :param as_pdf: Return as PDF. Default False. - :param password: Password to encrypt the pdf with. Default None""" + :param password: Password to encrypt the pdf with. Default None + :param pdf_generator: PDF generator to use. Default 'wkhtmltopdf' + """ from frappe.utils.pdf import get_pdf from frappe.website.serve import get_response_without_exception_handling """ - local.form_dict.chrome_pdf_generator is set from before_request hook (print designer app) for download_pdf endpoint + local.form_dict.pdf_generator is set from before_request hook (print designer app) for download_pdf endpoint if it is not set (internal function call) then set it """ - if "chrome_pdf_generator" not in local.form_dict: + if "pdf_generator" not in local.form_dict: # if arg is passed, use that, else get setting from print format - if chrome_pdf_generator is None: - chrome_pdf_generator = frappe.get_cached_value( - "Print Format", print_format, "chrome_pdf_generator" + if pdf_generator is None: + pdf_generator = ( + frappe.get_cached_value("Print Format", print_format, "pdf_generator") or "wkhtmltopdf" ) - local.form_dict.chrome_pdf_generator = bool(cint(chrome_pdf_generator)) + local.form_dict.pdf_generator = pdf_generator original_form_dict = copy.deepcopy(local.form_dict) try: @@ -2129,16 +2131,24 @@ def get_print( if not as_pdf: return html - if local.form_dict.chrome_pdf_generator: - hook_func = frappe.get_hooks("chrome_pdf_generator") - if hook_func: - return frappe.call( - hook_func[-1], + if local.form_dict.pdf_generator != "wkhtmltopdf": + hook_func = frappe.get_hooks("pdf_generator") + for hook in hook_func: + """ + check pdf_generator value in your hook function. + if it matches run and return pdf else return None + """ + pdf = frappe.call( + hook, print_format=print_format, html=html, options=pdf_options, output=output, + pdf_generator=local.form_dict.pdf_generator, ) + # if hook returns a value, assume it was the correct pdf_generator and return it + if pdf: + return pdf return get_pdf(html, options=pdf_options, output=output) diff --git a/frappe/printing/doctype/print_format/print_format.py b/frappe/printing/doctype/print_format/print_format.py index f8e2a594f4..4e5029944b 100644 --- a/frappe/printing/doctype/print_format/print_format.py +++ b/frappe/printing/doctype/print_format/print_format.py @@ -22,7 +22,6 @@ class PrintFormat(Document): absolute_value: DF.Check align_labels_right: DF.Check - chrome_pdf_generator: DF.Check css: DF.Code | None custom_format: DF.Check default_print_language: DF.Link | None @@ -41,6 +40,7 @@ class PrintFormat(Document): page_number: DF.Literal[ "Hide", "Top Left", "Top Center", "Top Right", "Bottom Left", "Bottom Center", "Bottom Right" ] + pdf_generator: DF.Literal["wkhtmltopdf"] print_format_builder: DF.Check print_format_builder_beta: DF.Check print_format_type: DF.Literal["Jinja", "JS"] diff --git a/frappe/templates/print_formats/pdf_header_footer_chrome.html b/frappe/templates/print_formats/pdf_header_footer_chrome.html deleted file mode 100644 index 0cb2857340..0000000000 --- a/frappe/templates/print_formats/pdf_header_footer_chrome.html +++ /dev/null @@ -1,49 +0,0 @@ - - -
- - {% for tag in head -%} - {{ tag | string }} - {%- endfor %} - - - - {% for tag in styles -%} - {{ tag | string }} - {%- endfor %} - - -