diff --git a/lms/lms/doctype/lms_certificate/lms_certificate.py b/lms/lms/doctype/lms_certificate/lms_certificate.py index 3c5f4de8..8d01b63d 100644 --- a/lms/lms/doctype/lms_certificate/lms_certificate.py +++ b/lms/lms/doctype/lms_certificate/lms_certificate.py @@ -6,6 +6,7 @@ from frappe import _ from frappe.model.document import Document from frappe.utils import add_years, nowdate from frappe.utils.pdf import get_pdf +from weasyprint import HTML, CSS from lms.lms.utils import is_certified @@ -50,7 +51,18 @@ def create_certificate(course): @frappe.whitelist() -def get_certificate_pdf(html): +def get_certificate_pdf(html_str): + + html = HTML(string=html_str) + css = CSS( + string=""" + @page { + size: A4 landscape; + }""" + ) + main = html.render(stylesheets=[css]) + pdf = main.write_pdf() + frappe.local.response.filename = "certificate.pdf" - frappe.local.response.filecontent = get_pdf(html, {"orientation": "LandScape"}) + frappe.local.response.filecontent = pdf frappe.local.response.type = "pdf" diff --git a/lms/lms/print_format/__init__.py b/lms/lms/print_format/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/lms/lms/print_format/certificate/__init__.py b/lms/lms/print_format/certificate/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/lms/templates/certificate.html b/lms/templates/certificate.html index 245970cb..c07aaf40 100644 --- a/lms/templates/certificate.html +++ b/lms/templates/certificate.html @@ -2,8 +2,7 @@