Print files from list view of Module and Subpanel

How to add print file button in Action menu of  record.?

When the user selects records in the list view (module) or is viewing the records in the subpanel, clicking on the Print Files button will cause the files in those records to mass print.  (Makes it more of a one step process to print instead of having to open each file, open the download, print the download one at a time.)

  • Hi I am using jsgrouping to print the files . I have implemented it but  somehow i am not able to print the pdf file from record. 

    As you can see , i want to print the content of file 'C20-02633 79.pdf'. How can i print the content of the pdf file. Please suggest me any way.

  • Can you share the code which triggers the print functionality? My initial guess is that you're printing current window instead of the file itself. 

  •  generateAndPrint: function (model) { console.log("In Generate Print label");
                        if (_.isEmpty(model) === false) {
                            
                            var apiUrl = app.api.buildURL("printEmailFile", "create", requestParams, {});
                            var edocIds = [];
    
                            edocIds.push({
                                edocIds: this.model.get("id"),
                            });
    
                            var requestParams = {
                                edocIds: edocIds, 
                            }; 
    						console.log("edocIds Id  : "+this.model.get("id"));
    						console.log("API URL  : "+apiUrl);
                            app.api.call("create", apiUrl, requestParams, null, { success: this.printLabels.bind(this) });
                        }
                    },
                    printLabels: function (data) { console.log("==="+JSON.stringify(data));
                        if (_.isEmpty(data) === false) {
                           window.print();
                        }  
                    },

    I am using the window.print(); , but i don't know how to get the pdf content and print it. 

  • <?php
    
    if (!defined('sugarEntry') || !sugarEntry) {
        die('Not A Valid Entry Point');
    } 
    class printEmailFileApi extends ModuleApi
    {
        public function registerApiRest()
        {
    
            return array(
                'printEmailFiles'    => array(
                    'reqType'   => 'POST',
                    'path'      => array('printEmailFile'),
                    'pathVars'  => array(''),
                    'method'    => 'printEmailFileData',
                    'shortHelp' => '',
                    'longHelp'  => '',
                ), 
            );
        }
    
        public function printEmailFileData(RestService $api, array $args): array
        {
            global $current_user; 
            global $timedate;
    
            $data         = array();
            $records      = array();
            $file_id	   =  $args["edocIds"];
    		
            //get the file location
    		//$file->temp_file_location = UploadFile::get_upload_path($file_id);
    		//$file_contents = $file->get_file_contents();
    
            $data['fileData'] = 'fffff';//$file_contents;
    
            return $data;
        }
    	
    	 
    }

    I am trying with 

    $file->temp_file_location = UploadFile::get_upload_path($file_id);
    $file_contents = $file->get_file_contents();
    but it's not working
  • I just took a quick look at your code, and looks like you're using window.print - that will not work, since it will only print your current page.

    But - try with print.js - it's a simpler option:

    Download the print.js from https://github.com/crabbly/Print.js/releases/tag/v1.3.1 and include it in your jsGroupings.

    Download the CSS file and add it in your custom.less with 

    @import (inline) 'print.min.css';

    Then - in your JS code, when you click in the print button, all you have to do is:

    generateAndPrint: function () {
    printJS('index.php?entryPoint=download&id=a09ba29c-f98a-11ea-9864-ac2b6e3c0d93&type=Notes')
    },

    I am just using download entrypoint for example - since it's easy and you don't have to pass authToken.

  • Thank you so much. I will try by this way.

  • I have downloaded the files from mentioned link but there are bunch of files in zip . Should we need to upload all these files to Sugar? And how these would be called in sugar ? Can you please explain.

  • Please follow the documentation from printjs site here :.  https://printjs.crabbly.com

  • Hi  I am not able to understand from the documentation, As there is no documentation for sugar crm. Would you please explain me more ?

  • Just repeating what I explained earlier - also I can only provide hints, the implementation is on you :) 

    Don't download the zip. Just download the javascript file and css file from:

    Download the javascript file - print.js from https://github.com/crabbly/Print.js/releases/tag/v1.3.1 and include it in your jsGroupings.

    Download the CSS file and add it in your custom.less with 

    @import (inline) 'print.min.css';

    Then - in your record.js code, when you click in the print button, in the event handler, all you have to do is to call the printJS code, something like:

    generateAndPrint: function () {
    printJS('index.php?entryPoint=download&id=a09ba29c-f98a-11ea-9864-ac2b6e3c0d93&type=Notes')
    },

    I am just using download entrypoint for example - since it's easy and you don't have to pass authToken. But you can also call your own entryPoint - don't use Rest API since printJS cannot pass OAuth-Token.