diff --git a/frappe/core/doctype/communication/communication.py b/frappe/core/doctype/communication/communication.py index 5f204d887f..3025045a94 100644 --- a/frappe/core/doctype/communication/communication.py +++ b/frappe/core/doctype/communication/communication.py @@ -129,11 +129,16 @@ def send_comm_email(d, name, sent_via=None, print_html=None, attachments='[]', s if print_html: print_html = scrub_urls(print_html) - send_print_as_pdf = cint(frappe.db.get_value("Outgoing Email Settings", "Outgoing Email Settings", "send_print_as_pdf")) + outgoing_email_settings = frappe.get_doc("Outgoing Email Settings", "Outgoing Email Settings") + send_print_as_pdf = cint(outgoing_email_settings.send_print_as_pdf) if send_print_as_pdf: try: - mail.add_pdf_attachment(name.replace(' ','').replace('/','-') + '.pdf', print_html) + options = { + 'page-size': outgoing_email_settings.pdf_page_size or 'A4' + } + mail.add_pdf_attachment(name.replace(' ','').replace('/','-') + '.pdf', print_html, + options=options) except Exception: frappe.msgprint(_("Error generating PDF, attachment sent as HTML")) send_print_as_pdf = 0 diff --git a/frappe/core/doctype/outgoing_email_settings/outgoing_email_settings.json b/frappe/core/doctype/outgoing_email_settings/outgoing_email_settings.json index 71630fcafc..d0e8903cbd 100644 --- a/frappe/core/doctype/outgoing_email_settings/outgoing_email_settings.json +++ b/frappe/core/doctype/outgoing_email_settings/outgoing_email_settings.json @@ -80,6 +80,15 @@ "label": "Send Attached Document Print as PDF", "permlevel": 0 }, + { + "default": "A4", + "depends_on": "eval:doc.send_print_as_pdf", + "fieldname": "pdf_page_size", + "fieldtype": "Select", + "label": "PDF Page Size", + "options": "A4\nLetter", + "permlevel": 0 + }, { "fieldname": "section_break_10", "fieldtype": "Section Break", @@ -98,7 +107,7 @@ "idx": 1, "in_create": 1, "issingle": 1, - "modified": "2014-07-09 01:47:56.027654", + "modified": "2014-07-11 06:21:27.062249", "modified_by": "Administrator", "module": "Core", "name": "Outgoing Email Settings", diff --git a/frappe/utils/email_lib/email_body.py b/frappe/utils/email_lib/email_body.py index 4cbe3cd3ce..12e94b5f3a 100644 --- a/frappe/utils/email_lib/email_body.py +++ b/frappe/utils/email_lib/email_body.py @@ -146,10 +146,10 @@ class EMail: self.msg_root.attach(part) - def add_pdf_attachment(self, name, html): + def add_pdf_attachment(self, name, html, options=None): import pdfkit, os fname = os.path.join("/tmp", frappe.generate_hash() + ".pdf") - pdfkit.from_string(html, fname) + pdfkit.from_string(html, fname, options=options or {}) with open(fname, "rb") as fileobj: self.add_attachment(name, fileobj.read(), 'application/octet-stream') os.remove(fname)