Merge pull request #35525 from Rl0007/fix/email-print-format-render

fix: render PDF based on print format type
This commit is contained in:
Hussain Nagaria 2026-02-09 19:04:26 +05:30 committed by GitHub
commit 956bc2cec8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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,29 @@ def attach_print(
frappe.local.flags.ignore_print_permissions = True
is_weasyprint_print_format = False
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")
)
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 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")