-
Notifications
You must be signed in to change notification settings - Fork 64
Label Printer
lasalesi edited this page Jun 11, 2018
·
2 revisions
The Label Printer is an additional feature that allows to generate custom-sized pdfs, which can then be used ot print labels. The implementation is very simply and can be done in a custom script, so labels can be added to any existing ERPNext doctype.
Add a snippet like the following in your custom script
frappe.ui.form.on('Item', {
refresh: function(frm) {
frm.add_custom_button(__("Create Label"), function() {
create_label(frm);
}).addClass("btn-primary");
}
});
function create_label(frm) {
// reference to the Label Printer record to be used
var label_printer = "MyLabel";
// html-content of the label
var content = "<p>Item: " + frm.doc.item_name + "</p>";
var w = window.open(
frappe.urllib.get_full_url("/api/method/erpnextswiss.erpnextswiss.doctype.label_printer.label_printer.download_label"
+ "?label_reference=" + encodeURIComponent(label_printer)
+ "&content=" + encodeURIComponent(content))
);
if (!w) {
frappe.msgprint(__("Please enable pop-ups")); return;
}
}
This will create the required label pdf and download it to the browser.