I create custom button for print a specific print format but it did not work

when click on Label Print button then nothing will happen not show any error massage and not open printing page

frappe.ui.form.on('Delivery Note', {
    refresh: function(frm) {
        frm.add_custom_button(__('Lable Print'), function() {
            // Replace 'your_custom_format_name' with the actual name of your custom print format
            frappe.call({
                method: 'frappe.utils.print_format.download_pdf',
                 args: {
                    doctype: 'Delivery Note',
                    name: (frm.doc.name),
                    format: 'label_dn',
                 },
    callback: function(r) {
        
                if (r.message) {
                var w = window.open(r.message);
                    if (!w) {
                        frappe.msgprint(__('Please enable pop-ups for this site.'));
                    }
                }
                }
            });
        });
    }
});

Use this:

frappe.ui.form.on("Delivery Note", {
	refresh: function (frm) {
		frm.add_custom_button(__("Label Print"), function () {
			const w = window.open(
				frappe.urllib.get_full_url(`/api/method/frappe.utils.print_format.download_pdf?
					doctype=${encodeURIComponent("Delivery Note")}
					&name=${encodeURIComponent(frm.doc.name)}
					&format=${encodeURIComponent("label_dn")}`)
			);
			if (!w) {
				frappe.msgprint(__("Please enable pop-ups for this site."));
			}
		});
	},
});
1 Like

What there is problem in my code

See documentation of download_pdf:

You can’t only make an API call, it will send encoded data.

My concern is i want do this by method and argument . Can do little changes in my code format it will work. what should i change in my argument to send encoded data .

I think you misunderstood. I mean in response you will get encoded data.