Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: warn if wkhtmltopdf is invalid #26174

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion frappe/printing/page/print/print.js
Expand Up @@ -603,7 +603,26 @@ frappe.ui.form.PrintView = class {
},
});
}

async is_wkhtmltopdf_valid() {
const is_valid = await frappe.call({
method: "frappe.utils.pdf.is_wkhtmltopdf_valid",
});
maharshivpatel marked this conversation as resolved.
Show resolved Hide resolved
// function returns true or false
if (is_valid.message) 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) {
Expand All @@ -619,6 +638,7 @@ frappe.ui.form.PrintView = class {
return;
}
} else {
this.is_wkhtmltopdf_valid();
this.render_page("/api/method/frappe.utils.print_format.download_pdf?");
}
}
Expand Down
15 changes: 15 additions & 0 deletions frappe/utils/pdf.py
Expand Up @@ -352,6 +352,21 @@ def toggle_visible_pdf(soup):
tag.extract()


@frappe.whitelist()
def is_wkhtmltopdf_valid():
is_wkhtmltopdf_valid = frappe.cache.hget("is_wkhtmltopdf_valid", None)
maharshivpatel marked this conversation as resolved.
Show resolved Hide resolved

if not is_wkhtmltopdf_valid:
try:
res = subprocess.check_output(["wkhtmltopdf", "--version"])
is_wkhtmltopdf_valid = True if "qt" in res.decode("utf-8").lower() else False
maharshivpatel marked this conversation as resolved.
Show resolved Hide resolved
frappe.cache.hset("is_wkhtmltopdf_valid", None, is_wkhtmltopdf_valid)
maharshivpatel marked this conversation as resolved.
Show resolved Hide resolved
except Exception:
pass

return is_wkhtmltopdf_valid
maharshivpatel marked this conversation as resolved.
Show resolved Hide resolved


def get_wkhtmltopdf_version():
wkhtmltopdf_version = frappe.cache.hget("wkhtmltopdf_version", None)

Expand Down