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 2 commits
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
20 changes: 19 additions & 1 deletion frappe/printing/page/print/print.js
Expand Up @@ -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) {
Expand All @@ -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?");
}
}
Expand Down
13 changes: 13 additions & 0 deletions frappe/utils/pdf.py
Expand Up @@ -18,6 +18,7 @@
from frappe import _
from frappe.core.doctype.file.utils import find_file_by_url
from frappe.utils import scrub_urls
from frappe.utils.caching import redis_cache
from frappe.utils.jinja_globals import bundled_asset, is_rtl

PDF_CONTENT_ERRORS = [
Expand Down Expand Up @@ -352,6 +353,18 @@ def toggle_visible_pdf(soup):
tag.extract()


@frappe.whitelist()
@redis_cache(ttl=60 * 60)
def is_wkhtmltopdf_valid():
try:
res = subprocess.check_output(["wkhtmltopdf", "--version"])
is_wkhtmltopdf_valid = "qt" in res.decode("utf-8").lower()
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