Hello,
I’m trying to accomplish this:
- In List View select some records with the selection checkbox
- Call some functionality that displays a PDF containing information for the selected records.
I managed to pass the names of the selected records as parameters to a server method, generate html and transform the html to a PDF.
Unfortunately I don’t know how to handle the the binary data of the PDF in my Client Script.
I have done this:
Here is the Client Script:
frappe.listview_settings['Schluessel'] = {
hide_name_column: true,
onload(listview) {
listview.page.add_inner_button(__("GenPdf"), () => callGenPdf());
}
}
function callGenPdf() {
let checked_items = cur_list.get_checked_items(true);
frappe.call({
method: "my_app.my_app.doctype.schluessel.api.GenPdf",
args: {
"checked_items" : checked_items
},
callback: function(r) {
// How to handle the returned binary data?
msgprint(__("Simpler Returnwert: {0}", [r.message]));
}
});
}
This is the serverside code:
@frappe.whitelist()
def GenPdf(**args):
checked_items = args.get('checked_items')
# prepare checked_items for split(). Does anyone knows a better way?
checked_items = checked_items.replace("[", "")
checked_items = checked_items.replace("]", "")
checked_items = checked_items.replace("\"", "")
doc = MyDoc(checked_items.split(","))
template = "{%- for row in doc.checked_items -%} {{row}} <br>{%- endfor -%}"
html = frappe.render_template(template, {"doc" : doc})
print(html)
return get_pdf(html) # How to handle this in Client Script?
class MyDoc:
def __init__(self, checked_items) -> None:
self.checked_items = checked_items
And that’s the result:
Currently I have no idea what to do with the returned value. How can I persuade the browser to output it as a PDF?