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.)

Parents Reply Children
  • I'm assuming that you're trying to print the file displayed in the Record: C20xxx.pdf directly from the browser, instead of the user having to download and print it manually.

    You could create a custom button in the record view dropdown by following these steps: https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.1/Cookbook/Adding_Buttons_to_the_Record_View/

    Once you have defined the custom event and handler in record.js, the trick is get an absolute URL of the PDF file. This is usually in the format:

    SITE_URL/rest/v11_8/Notes/RECORD_ID/file/filename?force_download=0&platform=base

    Note that the force_download is 0, which will just display the PDF.

    Then there are probably a couple of ways to trigger the print:

    Option #1 - Use window.open - this will open the file in a new tab and invoke print:

    window.open("FILE_URL").print()

    Option #2  - is to use libraries, one such example is print.js - this will trigger print without viewing the PDF file but in the same window. To use this JS, you may have to add this JS to jsgroups: https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.1/Architecture/Extensions/JSGroupings/

  • Thanks For your quick response.

  • 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. 

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

  • 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