def get_print(doctype=None, name=None, print_format=None, style=None, html=None, as_pdf=False, doc=None, output=None): """Get Print Format for given document. :param doctype: DocType of document. :param name: Name of document. :param print_format: Print Format name. Default 'Standard', :param style: Print Format style. :param as_pdf: Return as PDF. Default False.""" from frappe.website.render import build_page from frappe.utils.pdf import get_pdf local.form_dict.doctype = doctype local.form_dict.name = name local.form_dict.format = print_format local.form_dict.style = style local.form_dict.doc = doc if not html: html = build_page("printview") if as_pdf: return get_pdf(html, output=output) else: return html
def download_multi_pdf_html_combined(doctype, name, format=None, cover_doctype=None, cover_name=None, cover_format=None, orientation="Portrait", letterhead=None): # name can include names of many docs of the same doctype. import json result = json.loads(name) if cover_name and cover_doctype and cover_format: html = frappe.get_print(cover_doctype, cover_name, cover_format, doc=None) else: html = "" # Concatenating pdf files output = "" for i, ss in enumerate(result): output = frappe.get_print(doctype, ss, format, doc=None) html = str(html) + str(output) frappe.local.response.filename = "{doctype}.pdf".format( doctype=doctype.replace(" ", "-").replace("/", "-")) frappe.local.response.filecontent = get_pdf(html, {"orientation": orientation}) frappe.local.response.type = "download"
def get_print(doctype=None, name=None, print_format=None, style=None, html=None, as_pdf=False, doc=None, output = None, no_letterhead = 0): """Get Print Format for given document. :param doctype: DocType of document. :param name: Name of document. :param print_format: Print Format name. Default 'Standard', :param style: Print Format style. :param as_pdf: Return as PDF. Default False.""" from frappe.website.render import build_page from frappe.utils.pdf import get_pdf local.form_dict.doctype = doctype local.form_dict.name = name local.form_dict.format = print_format local.form_dict.style = style local.form_dict.doc = doc local.form_dict.no_letterhead = no_letterhead if not html: html = build_page("printview") if as_pdf: return get_pdf(html, output = output) else: return html
def download_multi_pdf(doctype, name, format=None): # name can include names of many docs of the same doctype. totalhtml = "" # Pagebreak to be added between each doc html pagebreak = """<p style="page-break-after:always;"></p>""" options = {} import json result = json.loads(name) # Get html of each doc and combine including page breaks for i, ss in enumerate(result): html = frappe.get_print(doctype, ss, format) if i == len(result) - 1: totalhtml = totalhtml + html else: totalhtml = totalhtml + html + pagebreak frappe.local.response.filename = "{doctype}.pdf".format( doctype=doctype.replace(" ", "-").replace("/", "-")) # Title of pdf options.update({ 'title': doctype, }) frappe.local.response.filecontent = get_pdf(totalhtml, options) frappe.local.response.type = "download"
def get_print(doctype=None, name=None, print_format=None, style=None, html=None, as_pdf=False, doc=None, output = None, no_letterhead = 0, password=None): """Get Print Format for given document. :param doctype: DocType of document. :param name: Name of document. :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""" from frappe.website.render import build_page from frappe.utils.pdf import get_pdf local.form_dict.doctype = doctype local.form_dict.name = name local.form_dict.format = print_format local.form_dict.style = style local.form_dict.doc = doc local.form_dict.no_letterhead = no_letterhead options = None if password: options = {'password': password} if not html: html = build_page("printview") if as_pdf: return get_pdf(html, output = output, options = options) else: return html
def create_zugferd_pdf(docname, verify=True, format=None, doc=None, doctype="Sales Invoice", no_letterhead=0): try: html = frappe.get_print(doctype, docname, format, doc=doc, no_letterhead=no_letterhead) pdf = get_pdf(html) xml = create_zugferd_xml(docname) if xml: facturx_pdf = generate_facturx_from_binary(pdf, xml.encode('utf-8')) ## Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration. return facturx_pdf else: # failed to generate xml, fallback return get_pdf(html) except Exception as err: frappe.log_error("Unable to create zugferdPDF for {2}: {0}\n{1}".format(err, xml, docname), "ZUGFeRD") # fallback to normal pdf return get_pdf(html)
def custome_report_to_pdf(html, orientation="Landscape"): frappe.local.response.filename = "report.pdf" frappe.local.response.filecontent = get_pdf(html, { "orientation": orientation, 'page-size': 'A4' }) frappe.local.response.type = "download"
def download_multi_pdf(doctype, name, format=None): # name can include names of many docs of the same doctype. totalhtml = "" # Pagebreak to be added between each doc html pagebreak = """<p style="page-break-after:always;"></p>""" options = {} import json result = json.loads(name) # Get html of each doc and combine including page breaks for i, ss in enumerate(result): html = frappe.get_print(doctype, ss, format) if i == len(result) - 1: totalhtml = totalhtml + html else: totalhtml = totalhtml + html + pagebreak frappe.local.response.filename = "{doctype}.pdf".format(doctype=doctype.replace(" ", "-").replace("/", "-")) # Title of pdf options.update({"title": doctype}) frappe.local.response.filecontent = get_pdf(totalhtml, options) frappe.local.response.type = "download"
def preview_report_card(doc): doc = frappe._dict(json.loads(doc)) doc.students = [doc.student] if not (doc.student_name and doc.student_batch): program_enrollment = frappe.get_all( "Program Enrollment", fields=["student_batch_name", "student_name"], filters={ "student": doc.student, "docstatus": ('!=', 2), "academic_year": doc.academic_year }) if program_enrollment: doc.batch = program_enrollment[0].student_batch_name doc.student_name = program_enrollment[0].student_name # get the assessment result of the selected student values = get_formatted_result( doc, get_course=True, get_all_assessment_groups=doc.include_all_assessment) assessment_result = values.get("assessment_result").get(doc.student) courses = values.get("course_dict") course_criteria = get_courses_criteria(courses) # get the assessment group as per the user selection if doc.include_all_assessment: assessment_groups = get_child_assessment_groups(doc.assessment_group) else: assessment_groups = [doc.assessment_group] # get the attendance of the student for that peroid of time. doc.attendance = get_attendance_count(doc.students[0], doc.academic_year, doc.academic_term) template = "erpnext/education/doctype/student_report_generation_tool/student_report_generation_tool.html" base_template_path = "frappe/www/printview.html" from frappe.www.printview import get_letter_head letterhead = get_letter_head(frappe._dict({"letter_head": doc.letterhead}), not doc.add_letterhead) html = frappe.render_template( template, { "doc": doc, "assessment_result": assessment_result, "courses": courses, "assessment_groups": assessment_groups, "course_criteria": course_criteria, "letterhead": letterhead.content, "add_letterhead": doc.add_letterhead if doc.add_letterhead else 0 }) final_template = frappe.render_template(base_template_path, { "body": html, "title": "Report Card" }) frappe.response.filename = "Report Card " + doc.students[0] + ".pdf" frappe.response.filecontent = get_pdf(final_template) frappe.response.type = "download"
def irs_1099_print(filters): if not filters: frappe._dict({ "company": frappe.db.get_default("Company"), "fiscal_year": frappe.db.get_default("fiscal_year") }) else: filters = frappe._dict(json.loads(filters)) company_address = get_payer_address_html(filters.company) company_tin = frappe.db.get_value("Company", filters.company, "tax_id") columns, data = execute(filters) template = frappe.get_doc("Print Format", "IRS 1099 Form").html output = PdfFileWriter() for row in data: row["company"] = filters.company row["company_tin"] = company_tin row["payer_street_address"] = company_address row["recipient_street_address"], row[ "recipient_city_state"] = get_street_address_html( "Supplier", row.supplier) row["payments"] = fmt_money(row["payments"], precision=0, currency="USD") frappe._dict(row) print(row) pdf = get_pdf(render_template(template, row), output=output if output else None) print(pdf) frappe.local.response.filename = filters.fiscal_year + " " + filters.company + " IRS 1099 Forms" frappe.local.response.filecontent = read_multi_pdf(output) frappe.local.response.type = "download"
def download_pdf(doctype, name, format=None, doc=None, no_letterhead=0): html = frappe.get_print(doctype, name, format, doc=doc, no_letterhead=no_letterhead) frappe.local.response.filename = "{name}.pdf".format(name=name.replace(" ", "-").replace("/", "-")) if doctype == "Pick List" and format == "Pick List 4*6": frappe.local.response.filecontent = get_pdf(html) else: frappe.local.response.filecontent = frappe.utils.pdf.get_pdf(html) frappe.local.response.type = "pdf"
def test_pdf_encryption(self): password = "******" pdf = pdfgen.get_pdf(self.html, options={"password": password}) reader = PdfFileReader(io.BytesIO(pdf)) self.assertTrue(reader.isEncrypted) if six.PY2: password = frappe.safe_encode(password) self.assertTrue(reader.decrypt(password))
def download_pdf(doctype, name, format=None): html = frappe.get_print(doctype, name, format) frappe.local.response.filename = "{name}.pdf".format(name=name.replace(" ", "-").replace("/", "-")) options = {} frappe.local.response.filecontent = get_pdf(html,options) frappe.local.response.type = "download"
def download_pdf(doctype, name, format=None, doc=None, no_letterhead=0): html = frappe.get_print(doctype, name, format, doc=doc, no_letterhead=no_letterhead) frappe.local.response.filename = "{name}.pdf".format( name=name.replace(" ", "-").replace("/", "-")) frappe.local.response.filecontent = get_pdf(html) frappe.local.response.type = "pdf"
def send_statements(company=None, manual=None): """ Send out customer statements """ show_progress = manual progress_title = _("Sending customer statements...") if show_progress: publish_progress(percent=0, title=progress_title) if company is None: company = frappe.db.get_single_value('Customer Statements Sender', 'company') if not company: frappe.throw( _('Company field is required on Customer Statements Sender')) exit() email_list = get_recipient_list() idx = 0 total = len(email_list) for row in email_list: idx += 1 if row.email_id is not None: if row.send_statement == "Yes": if show_progress: publish_progress( percent=(idx / total * 100), title=progress_title, description=' Creating PDF for {0}'.format( row.customer)) data = get_report_content(company, row.customer) # Get PDF Data pdf_data = get_pdf(data) if not pdf_data: return attachments = [{ 'fname': get_file_name(), 'fcontent': pdf_data }] frappe.sendmail( recipients=row.email_id, subject='Customer Statement from {0}'.format(company), message= 'Good day. <br> Please find attached your latest statement from {0}' .format(company), attachments=attachments, reference_doctype="Report", reference_name="General Ledger") if show_progress: publish_progress(percent=100, title=progress_title) frappe.msgprint('Emails queued for sending')
def get_item_label(docname): doc = frappe.db.get_values( "Item", docname, ["item_name", "item_code"], as_dict=True, )[0] html = frappe.render_template("templates/pages/item_label.html", dict(doc=doc)) frappe.local.response.filename = f"Item_{doc.item_code}_label.pdf" frappe.local.response.filecontent = get_pdf(html, pdf_options) frappe.local.response.type = "download"
def get_label(docname): doc = frappe.db.get_values( "Freezer", docname, ["customer_name", "freezer_no"], as_dict=True, )[0] html = frappe.render_template("templates/pages/freezer_label.html", dict(doc=doc)) frappe.local.response.filename = f"Freezer_{doc.freezer_no}_label.pdf" frappe.local.response.filecontent = get_pdf(html, pdf_options) frappe.local.response.type = "download"
def send_email_to_manager(): """ Send email to the manager :return: """ use_daily_email = frappe.db.get_single_value('POS Bahrain Settings', 'use_daily_email') if not use_daily_email: return manager_email = frappe.db.get_single_value('POS Bahrain Settings', 'manager_email') if not manager_email: frappe.throw( _('Manager email not set. Set it at POS Bahrain Settings.')) yesterday_date = add_days(frappe.utils.nowdate(), -1) filters = { 'company': frappe.defaults.get_user_default("company"), 'from_date': yesterday_date, 'to_date': yesterday_date, 'group_by': 'Invoice' } report = frappe.get_doc('Report', 'Gross Profit') columns, data = report.get_data(limit=100, filters=filters, as_dict=True) columns.insert(0, frappe._dict(fieldname='idx', label='', width='30px')) for i in range(len(data)): data[i]['idx'] = i + 1 html = frappe.render_template( 'frappe/templates/emails/auto_email_report.html', { 'title': 'Gross Profit', 'description': 'Daily Gross Profit', 'columns': columns, 'data': data, 'report_name': 'Gross Profit' }) frappe.sendmail(recipients=[manager_email], subject='Gross Profit Daily', message=_('See attachments below'), attachments=[{ 'fname': 'gross_profit_daily.pdf', 'fcontent': get_pdf(html, {'orientation': 'Landscape'}) }])
def download_pdf(doctype, name, format=None, doc=None, no_letterhead=0): options = {} options.update({'footer-spacing': '0', 'header-spacing': '0'}) html = frappe.get_print(doctype, name, format, doc=doc, no_letterhead=no_letterhead) frappe.local.response.filename = "{name}.pdf".format( name=name.replace(" ", "-").replace("/", "-")) frappe.local.response.filecontent = get_pdf(html, options) frappe.local.response.type = "download"
def dpdf(dt, dn, ft=None, doc=None, nl=0, lh=None, on="Portrait", sn=None): html = frappe.get_print(dt, dn, ft, doc=doc, no_letterhead=nl, letterhead=lh, sign_type=sn) frappe.local.response.filename = "{name}.pdf".format( name=dn.replace(" ", "-").replace("/", "-")) frappe.local.response.filecontent = get_pdf(html, {"orientation": on}) frappe.local.response.type = "pdf"
def download_print_at_home_pdf(name): doctype = "Gutschein" format = 'print@home' doc = None no_letterhead = 0 html = frappe.get_print(doctype, name, format, doc=doc, no_letterhead=no_letterhead) frappe.local.response.filename = "{name}.pdf".format( name=name.replace(" ", "-").replace("/", "-")) frappe.local.response.filecontent = get_pdf(html) frappe.local.response.type = "download"
def html_to_pdf(html, name): frappe.local.response.filename = "{name}.pdf".format(name=name.replace(" ", "-").replace("/", "-")) options = {} # Title of pdf options.update({ 'title': name, }) import json result = json.loads(html) frappe.local.response.filecontent = get_pdf(result,options) frappe.local.response.type = "download"
def download_pdf(doctype, name, format=None, doc=None): opts = { "page-size": "A4", } if doctype in ("Orden de Produccion", ): opts = { "page-size": "Legal", } html = frappe.get_print(doctype, name, format, doc=doc) frappe.local.response.filename = "{name}.pdf".format( name=name.replace(" ", "-").replace("/", "-")) frappe.local.response.filecontent = get_pdf(html, opts) frappe.local.response.type = "download"
def download_vorschau_pdf(): doctype = "Gutschein" name = 'Gutschein-000001' format = 'Vorschau' doc = None no_letterhead = 0 html = frappe.get_print(doctype, name, format, doc=doc, no_letterhead=no_letterhead) frappe.local.response.filename = "{name}.pdf".format( name=name.replace(" ", "-").replace("/", "-")) frappe.local.response.filecontent = get_pdf(html) frappe.local.response.type = "download"
def get_print_format(doctype, name, print_format=None, style=None, as_pdf=False): from frappe.website.render import build_page from frappe.utils.pdf import get_pdf local.form_dict.doctype = doctype local.form_dict.name = name local.form_dict.format = print_format local.form_dict.style = style html = build_page("print") if as_pdf: return get_pdf(html) else: return html
def preview_report_card(doc): doc = frappe._dict(json.loads(doc)) doc.students = [doc.student] if not (doc.student_name and doc.student_batch): program_enrollment = frappe.get_all("Program Enrollment", fields=["student_batch_name", "student_name"], filters={"student": doc.student, "docstatus": ('!=', 2), "academic_year": doc.academic_year}) if program_enrollment: doc.batch = program_enrollment[0].student_batch_name doc.student_name = program_enrollment[0].student_name # get the assessment result of the selected student values = get_formatted_result(doc, get_course=True, get_all_assessment_groups=doc.include_all_assessment) assessment_result = values.get("assessment_result").get(doc.student) courses = values.get("course_dict") course_criteria = get_courses_criteria(courses) # get the assessment group as per the user selection if doc.include_all_assessment: assessment_groups = get_child_assessment_groups(doc.assessment_group) else: assessment_groups = [doc.assessment_group] # get the attendance of the student for that peroid of time. doc.attendance = get_attendance_count(doc.students[0], doc.academic_year, doc.academic_term) template = "erpnext/education/doctype/student_report_generation_tool/student_report_generation_tool.html" base_template_path = "frappe/www/printview.html" from frappe.www.printview import get_letter_head letterhead = get_letter_head(frappe._dict({"letter_head": doc.letterhead}), not doc.add_letterhead) html = frappe.render_template(template, { "doc": doc, "assessment_result": assessment_result, "courses": courses, "assessment_groups": assessment_groups, "course_criteria": course_criteria, "letterhead": letterhead.content, "add_letterhead": doc.add_letterhead if doc.add_letterhead else 0 }) final_template = frappe.render_template(base_template_path, {"body": html, "title": "Report Card"}) frappe.response.filename = "Report Card " + doc.students[0] + ".pdf" frappe.response.filecontent = get_pdf(final_template) frappe.response.type = "download"
def download_pdf(doctype, name, format=None): from flows.stdlogger import root root.debug((doctype, name, format)) if "[" not in name: name = '["{}"]'.format(name) pages = [] name_list = json.loads(name) for id in name_list: pages.append(frappe.get_print_format(doctype, id, format)) html = """<div class="page-break"></div>""".join(pages) frappe.local.response.filename = "{name}.pdf".format( name=name_list[0].replace(" ", "-").replace("/", "-")) frappe.local.response.filecontent = get_pdf(html) frappe.local.response.type = "download"
def get_claim_pdf_file(doc): doctype = doc.doctype docname = doc.name default_print_format = frappe.db.get_value( "Property Setter", dict(property="default_print_format", doc_type=doctype), "value", ) if default_print_format: print_format = default_print_format else: print_format = "NHIF Form 2A & B" # print_format = "NHIF Form 2A & B" html = frappe.get_print(doctype, docname, print_format, doc=None, no_letterhead=1) filename = "{name}-claim".format( name=docname.replace(" ", "-").replace("/", "-")) pdf = get_pdf(html) if pdf: ret = frappe.get_doc({ "doctype": "File", "attached_to_doctype": doc.doctype, "attached_to_name": docname, "folder": "Home/Attachments", "file_name": filename + ".pdf", "file_url": "/private/files/" + filename + ".pdf", "content": pdf, "is_private": 1, }) ret.insert(ignore_permissions=True) ret.db_update() if not ret.name: frappe.throw("ret name not exist") base64_data = to_base64(pdf) return base64_data else: frappe.throw(_("Failed to generate pdf"))
def download_pdf(doctype, name, format=None, doc=None, print_format=None): if print_format in ["Microsoft Certificate", "Microsoft Zertifikat"]: orientation = "Landscape" html = frappe.get_print(doctype, name, format, doc=doc, as_pdf=True, orientation=orientation) frappe.local.response.filename = "{name}.pdf".format( name=name.replace(" ", "-").replace("/", "-")) frappe.local.response.filecontent = html frappe.local.response.type = "download" else: html = frappe.get_print(doctype, name, format, doc=doc) frappe.local.response.filename = "{name}.pdf".format( name=name.replace(" ", "-").replace("/", "-")) frappe.local.response.filecontent = get_pdf(html) frappe.local.response.type = "download"
def create_pdf(): doctype = "Sales Invoice" name = "ACC-SINV-2020-00001" format = None doc = None no_letterhead = 0 html = frappe.get_print(doctype, name, format, doc=doc, no_letterhead=no_letterhead) pdf = get_pdf(html) xml = create_zugferd_xml(name) facturxPDF = generate_facturx_from_binary(pdf, xml) newFile = open("filename.pdf", "wb") newFile.write(facturxPDF) return
def download_pdf(doctype, name, format=None, doc=None, no_letterhead=0, letterhead=None, orientation="Portrait", sign_type=None): html = frappe.get_print(doctype, name, format, doc=doc, no_letterhead=no_letterhead, letterhead=letterhead, sign_type=sign_type) frappe.local.response.filename = "{name}.pdf".format( name=name.replace(" ", "-").replace("/", "-")) frappe.local.response.filecontent = get_pdf(html, {"orientation": orientation}) frappe.local.response.type = "pdf"
def create_pdf(from_date, from_shift, to_date, to_shift): get_data = frappe.db.sql( """SELECT quotation_to, customer_name, transaction_date, shift, valid_till, contact_mobile, total, total_taxes_and_charges, grand_total FROM `tabQuotation` WHERE transaction_date='{}' AND shift IN('{}','Evening') AND docstatus=1 UNION SELECT quotation_to, customer_name, transaction_date, shift, valid_till, contact_mobile, total, total_taxes_and_charges, grand_total FROM `tabQuotation` WHERE transaction_date>'{}' AND transaction_date<'{}' AND docstatus=1 UNION SELECT quotation_to, customer_name, transaction_date, shift, valid_till, contact_mobile, total, total_taxes_and_charges, grand_total FROM `tabQuotation` WHERE transaction_date='{}' AND shift IN('Morning','{}') AND docstatus=1 """.format(from_date, from_shift, from_date, to_date, to_date, to_shift), as_dict=1) data = [] data.extend(get_data) context = {"records": data} template = frappe.render_template( "agency_management/public/js/page_templates/page_print_format.html", context) pdf = get_pdf(template) with open('/home/ruturaj/Downloads/report.pdf', 'wb') as file: file.write(pdf) return pdf
def letter_to_pdf(html, title, letterhead=None, attach=False, doctype=None, docname=None): html = get_formatted_letter(title, html, letterhead) pdf = get_pdf(html) if attach: try: private_files = frappe.get_site_path('private', 'files') fname = os.path.join( private_files, "{0}-{1}.pdf".format(title, frappe.generate_hash(length=6))) with open(fname, "wb") as f: f.write(pdf) new_file = frappe.get_doc({ "doctype": "File", "file_name": title, "attached_to_doctype": doctype, "attached_to_name": docname, "is_private": 1, "file_url": "/private/files/" + fname.split('/private/files/')[1] }) new_file.insert() except Exception: frappe.log_error("Letter error", frappe.get_traceback()) frappe.local.response.filename = "{0}.pdf".format( title.replace(" ", "-").replace("/", "-")) frappe.local.response.filecontent = pdf frappe.local.response.type = "pdf"
def download_pdf(selected_items): # parse parameter to list if isinstance(selected_items, str): selected_items = selected_items.split("|") # get raw data items = [] for s in selected_items: doc = frappe.get_doc("Bemusterung", s) items.append({ 'name': doc.name, 'image': doc.image, 'stoffbreite_von': doc.stoffbreite_von, 'stoffbreite_bis': doc.stoffbreite_bis, 'fertigbreite_von': doc.fertigbreite_von, 'fertigbreite_bis': doc.fertigbreite_bis, 'gewicht': doc.gewicht, 'rate': 1.2 * float(doc.rate), 'country_of_origin': doc.country_of_origin, 'zusammensetzung': get_composition_string(doc.name), 'pflegesymbole': get_care_symbol_html(doc.name) }) data = { 'items': items, 'date': datetime.today().strftime('%d.%m.%Y'), 'doc': { 'customer': None } } # prepare content content = frappe.render_template( 'hoh/templates/pages/catalogue_print.html', data) options = {} # generate pdf filedata = get_pdf(content, options) # prepare for download frappe.local.response.filename = "hoferhecht_{0}.pdf".format( datetime.today().strftime('%Y-%m-%d')) frappe.local.response.filecontent = filedata frappe.local.response.type = "download"
def get_print_content(print_format, doctype, docname, is_escpos=False, is_raw=False): if is_escpos or is_raw: doc = frappe.get_doc(doctype, docname) template = frappe.db.get_value("Print Format", print_format, "html") content = render_template(template, {"doc": doc}) if is_escpos: content.replace("<br>", "<br/>") else: content = frappe.get_print(doctype, docname, print_format) if is_escpos: printer = IOPrinter() printer.receipt(content) raw = printer.get_content() elif is_raw: raw = content else: raw = get_pdf(content) #frappe.msgprint("<pre>%s</pre>" %raw) return b64encode(raw)
def add_pdf_attachment(self, name, html, options=None): self.add_attachment(name, get_pdf(html, options), 'application/octet-stream')
def report_to_pdf(html, orientation="Landscape"): frappe.local.response.filename = "report.pdf" frappe.local.response.filecontent = get_pdf(html, {"orientation": orientation}) frappe.local.response.type = "download"
def download_pdf(doctype, name, format=None, doc=None, no_letterhead=0): html = frappe.get_print(doctype, name, format, doc=doc, no_letterhead=no_letterhead) frappe.local.response.filename = "{name}.pdf".format(name=name.replace(" ", "-").replace("/", "-")) frappe.local.response.filecontent = get_pdf(html) frappe.local.response.type = "pdf"
def report_to_pdf(html): frappe.local.response.filename = "report.pdf" frappe.local.response.filecontent = get_pdf(html) frappe.local.response.type = "download"