Custom print button to print using specific format ( Or change print format selection programmatically)

For a doc, i have multiple print format that I need to use in multiple scenarios, currently what I am doing is selecting the required print format from the drop-down menu in the print preview list.

Is there any way where I can create a multiple print button for each print format which will automatically select required print format and open the print preview when clicked ? Or any other method / solution for this?

This will be a lot more convenient compared to what I am currently doing.

Solved it.

  1. added a field in doctype called "print_format_selector

  2. created custom button to call print function and set it to load on page refresh

     function custom_print(frm){
         cur_frm.add_custom_button(__("Button Name 1"), function() {
     cur_frm.add_custom_button(__("Button Name 2"), function() {
  3. Overrided the default print format fetching function and added an if condition to check if there exists any value in that field and if there exists any, return that value as the selected print format

     $.extend(frappe.meta, {
     get_print_formats: function(doctype) {
         var print_format_list = ["Standard"];
         var default_print_format = locals.DocType[doctype].default_print_format;
         let enable_raw_printing = frappe.model.get_doc(":Print Settings", "Print Settings").enable_raw_printing;
         var print_formats = frappe.get_list("Print Format", {doc_type: doctype})
             .sort(function(a, b) { return (a > b) ? 1 : -1; });
         $.each(print_formats, function(i, d) {
             if (
                 && d.print_format_type !== 'JS'
                 && (cint(enable_raw_printing) || !d.raw_printing)
             ) {
         if(default_print_format && default_print_format != "Standard") {
             var index = print_format_list.indexOf(default_print_format);
             print_format_list.splice(index, 1).sort();
         if(cur_frm.doc.print_format_selector){ //newly added if condition
             var print_format = [cur_frm.doc.print_format_selector]
             return print_format
             return print_format_list;

To override, i created a new file in apps/appname/appname/public/js/over_rided_func.js and included that file in build.json and also in did a bench build once, then bench --site sitename migrate, bench clear-cache, bench restart

in build.json

    "js/over_rided_func.js": [


doctype_js = {"MyDoctype" : "public/js/over_rided_func.js"}

Hi, i have this case but i don’t now how to enter your solution. The “$.extend” must be included on custom script doctype or inside the frappe proyect?

Best regards