2
0
mirror of https://github.com/frappe/frappe.git synced 2024-06-12 22:22:25 +00:00

chore: warn if wkhtmltopdf is invalid (#26174)

* chore: warn if wkhtmltopdf is invalid

wkhtmltopdf ( with patched qt ) is required to generate pdfs properly.
when user clicks on PDF, pdf will be generated and downloaded.
however, on print preview page warning will be shown.

* chore: refactor based on review comments

* chore: return False incase of exception

* chore: refactor and better naming

Co-authored-by: Ankush Menat <ankushmenat@gmail.com>
This commit is contained in:
Maharshi Patel 2024-04-30 16:06:56 +05:30 committed by GitHub
parent f244f3c76f
commit 6a6ded156f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 1 deletions

View File

@ -603,7 +603,24 @@ frappe.ui.form.PrintView = class {
},
});
}
async is_wkhtmltopdf_valid() {
const is_valid = await frappe.xcall("frappe.utils.pdf.is_wkhtmltopdf_valid");
// function returns true or false
if (is_valid) return;
frappe.msgprint({
title: __("Invalid wkhtmltopdf version"),
message:
__("PDF generation may not work as expected.") +
"<hr/>" +
__("Please contact your system manager to install correct version.") +
"<br/>" +
__("Correct version :") +
" <b><a href ='https://wkhtmltopdf.org/downloads.html'>" +
__("wkhtmltopdf 0.12.x (with patched qt).") +
"</a></b>",
indicator: "red",
});
}
render_pdf() {
let print_format = this.get_print_format();
if (print_format.print_format_builder_beta) {
@ -619,6 +636,7 @@ frappe.ui.form.PrintView = class {
return;
}
} else {
this.is_wkhtmltopdf_valid();
this.render_page("/api/method/frappe.utils.print_format.download_pdf?");
}
}

View File

@ -18,6 +18,7 @@ import frappe
from frappe import _
from frappe.core.doctype.file.utils import find_file_by_url
from frappe.utils import cstr, scrub_urls
from frappe.utils.caching import redis_cache
from frappe.utils.jinja_globals import bundled_asset, is_rtl
PDF_CONTENT_ERRORS = [
@ -352,6 +353,16 @@ def toggle_visible_pdf(soup):
tag.extract()
@frappe.whitelist()
@redis_cache(ttl=60 * 60)
def is_wkhtmltopdf_valid():
try:
output = subprocess.check_output(["wkhtmltopdf", "--version"])
return "qt" in output.decode("utf-8").lower()
except Exception:
return False
def get_wkhtmltopdf_version():
wkhtmltopdf_version = frappe.cache.hget("wkhtmltopdf_version", None)