Printing in Browsers not showing Workbook

Posted by: justin.arias on 9 March 2020, 3:15 pm EST

    • Post Options:
    • Link

    Posted 9 March 2020, 3:15 pm EST

    Some of our users using Edge have tried ‘Ctrl+P’ to print the page. However on the preview, the spreadsheet will not show up. This is the behavior also for some of sheets here:

    https://www.grapecity.com/demos/spread/JS/TutorialSample/Showcase/BusinessDashboard/purejs

    Some of these sheets and will not show in a print preview. This happens in chrome too but, is more prevalent in edge. Any tips? Thanks.

  • Posted 11 March 2020, 2:11 am EST

    Hi Justin,

    To be able to print the SJS workbook correctly, we need to use the workbook.print() method instead of the browser’s default print functionality. To allow users to print using the ctrl+p shortcut, we could create a custom command for print and add ctrl+p as a shortcut for the print command. Please refer to the following code snippet:

    // register customer print command
      var pCommand = wb => {
        wb.print();
        return true;
      };
      spread.commandManager().register("print", pCommand);
      // set shortcut key
      spread
        .commandManager()
        .setShortcutKey("print", 80, true, false, false, false); // 80 is keycode for 'p'
    

    You may also refer to the following samples:

    https://codesandbox.io/s/spread-js-starter-kthii

    https://www.grapecity.com/spreadjs/demos/features/print/custom-print/purejs

    Regards

    Sharad

  • Posted 12 March 2020, 1:18 am EST

    Take your time and let us know if you face any issues.

  • Posted 12 March 2020, 1:44 pm EST

    Thanks I’ll take a look into the documentation and try to set up a shortcut key. Thanks!

  • Posted 12 March 2020, 2:13 pm EST

    Hey Sharad, I was able to add a shortcut key and results are just as expected when pressing ‘Ctrl+P’, however there is one issue on closing the print preview dialog box. After closing another print preview dialog appears (most likely triggered by the browser).

    Does spread.print() prevent default behavior or do I need to add one in addition to it?

  • Posted 13 March 2020, 7:22 am EST

    Hi Justin,

    Make sure that that your custom command is returning true to inform SJS that command is executed successfully and we need to prevent the default behavior.

    If the issue persists, please share a small sample replicating the issue so that we could further investigate the issue.

    Regards

    Sharad

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels