From a86894377af2b62ccf963400c09cb41f743c6d7d Mon Sep 17 00:00:00 2001 From: Rahul Agrawal <12agrawalrahul@gmail.com> Date: Tue, 30 Dec 2025 13:20:34 +0530 Subject: [PATCH 1/3] fix: render PDF based on print format type --- frappe/utils/print_utils.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/frappe/utils/print_utils.py b/frappe/utils/print_utils.py index 6efa3a119c..55fdd17ca3 100644 --- a/frappe/utils/print_utils.py +++ b/frappe/utils/print_utils.py @@ -121,7 +121,8 @@ def attach_print( from frappe.utils.pdf import get_pdf print_settings = frappe.db.get_singles_dict("Print Settings") - + if print_letterhead and not letterhead: + letterhead = frappe.get_cached_value("Letter Head", {"is_default": 1}, "name") kwargs = dict( print_format=print_format, style=style, @@ -133,16 +134,26 @@ def attach_print( frappe.local.flags.ignore_print_permissions = True + custom_format = False + if print_format: + custom_format = frappe.get_cached_value("Print Format", print_format, "custom_format") + with print_language(lang or frappe.local.lang): content = "" if cint(print_settings.send_print_as_pdf): ext = ".pdf" - kwargs["as_pdf"] = True - content = ( - get_pdf(html, options={"password": password} if password else None) - if html - else get_print(doctype, name, **kwargs) - ) + if html: + content = get_pdf(html, options={"password": password} if password else None) + elif custom_format: + kwargs["as_pdf"] = True + content = get_print(doctype, name, **kwargs) + else: + from frappe.utils.weasyprint import PrintFormatGenerator + + doc_obj = doc or frappe.get_cached_doc(doctype, name) + letterhead_name = letterhead if print_letterhead else None + generator = PrintFormatGenerator(print_format, doc_obj, letterhead_name) + content = generator.render_pdf() else: ext = ".html" content = html or scrub_urls(get_print(doctype, name, **kwargs)).encode("utf-8") From 11a07f2e575bc82d3f84c798717e84c4bade27ee Mon Sep 17 00:00:00 2001 From: Rahul Agrawal <12agrawalrahul@gmail.com> Date: Tue, 30 Dec 2025 18:21:27 +0530 Subject: [PATCH 2/3] fix: support for print_designer --- frappe/utils/print_utils.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/frappe/utils/print_utils.py b/frappe/utils/print_utils.py index 55fdd17ca3..e18d7952bd 100644 --- a/frappe/utils/print_utils.py +++ b/frappe/utils/print_utils.py @@ -134,9 +134,12 @@ def attach_print( frappe.local.flags.ignore_print_permissions = True - custom_format = False + is_weasyprint_print_format = False if print_format: - custom_format = frappe.get_cached_value("Print Format", print_format, "custom_format") + print_format_doc = frappe.get_cached_doc("Print Format", print_format) + is_weasyprint_print_format = not ( + print_format_doc.custom_format or print_format_doc.get("print_designer_print_format") + ) with print_language(lang or frappe.local.lang): content = "" @@ -144,16 +147,16 @@ def attach_print( ext = ".pdf" if html: content = get_pdf(html, options={"password": password} if password else None) - elif custom_format: - kwargs["as_pdf"] = True - content = get_print(doctype, name, **kwargs) - else: + elif is_weasyprint_print_format: from frappe.utils.weasyprint import PrintFormatGenerator doc_obj = doc or frappe.get_cached_doc(doctype, name) letterhead_name = letterhead if print_letterhead else None generator = PrintFormatGenerator(print_format, doc_obj, letterhead_name) content = generator.render_pdf() + else: + kwargs["as_pdf"] = True + content = get_print(doctype, name, **kwargs) else: ext = ".html" content = html or scrub_urls(get_print(doctype, name, **kwargs)).encode("utf-8") From 45feea5b9a19e6d9f566fc0883aff64c7146183e Mon Sep 17 00:00:00 2001 From: Rahul Agrawal <12agrawalrahul@gmail.com> Date: Thu, 15 Jan 2026 08:48:40 +0530 Subject: [PATCH 3/3] fix: skip standard format --- frappe/utils/print_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/utils/print_utils.py b/frappe/utils/print_utils.py index e18d7952bd..a345c6be2c 100644 --- a/frappe/utils/print_utils.py +++ b/frappe/utils/print_utils.py @@ -135,7 +135,7 @@ def attach_print( frappe.local.flags.ignore_print_permissions = True is_weasyprint_print_format = False - if print_format: + if print_format and print_format != "Standard": print_format_doc = frappe.get_cached_doc("Print Format", print_format) is_weasyprint_print_format = not ( print_format_doc.custom_format or print_format_doc.get("print_designer_print_format")