Merge pull request #693 from anandpdoshi/anand-july-11
PDF page size option
This commit is contained in:
commit
58d8f6568b
3 changed files with 19 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue