Add direct print report to web client

IIRC it is not possible to trigger a print of a report from a web page.
Browsers only allow direct print of the current page. An example is the jQuery print this plugin

Could you please elaborate what is kiosk-printing or provide some links.
What browsers supports them? How it works?

Sometimes I use https://printjs.crabbly.com/ - after writing solutions by my own I changed to this because it is a nightmare to maintain it with wide browser support. In my opinion this lib is the most complete. Possibly you can adopt it in “custom.js” to consum the print action from sao.

In other environments (f.e. a browser solution for shipment handling with label printers) I us a simple printserver that consumes base64-data and call it via link or ajax

import cherrypy
from ezprinting import PrintJob
import base64

class PrintServer(object):

    @cherrypy.expose
    def index(self, printer_name, data):
    """
        printer names submitted should be known or you can rename them in cups 
        or fix it with something like:
        
        if printer_name == 'label':
              printer_name = 'robotron_nadeldrucker_1234'
        else:
              printer_name = 'veb_blaupause_KYB'
    """
      

             if not data:
                   return 
             try:
                  content = base64.urlsafe_b64decode(data)
             except Exception as e:
                   return str(e)
             pjob = PrintJob.new_cups(printer_name=printer_name, content=content)
             result = pjob.print()
             return result


 if __name__ == '__main__':
     conf = {
         '/': {
             'tools.response_headers.on': True,
             'tools.response_headers.headers': [
                     ('Access-Control-Allow-Origin', '*')],
             'server.socket_port': 8080
        }
    }
    cherrypy.quickstart(PrintServer(), '/', conf)
1 Like

I didn’t read before answering :slight_smile:
Direct printing without dialog and printing a document are two different issues.
It is possible to print a report - you do this by opening a frame (could be hidden) or a popup with the report (as base64) and trigger the good old print()
Disabling the dialog is an other issue - it can be achieved by browser specific settings like always_print_silent (if I remember right) in firefox, kiosk mode, plugins and other creepy stuff. I would vote against this feature if asked.

This seems like a simple solution that can be probably included on sao.

Which is the problem with the dialog? If we can hide it I see no issue.

BTW: Does the print work if we close the dialog (with javascript) before the user using the print button?

I mean the standard dialog to choose the printer. There are work arounds to direct print to the default printer, but all of them are hacky or depending on particular browser settings, plugins etc. Nn my opinion it is not worth it.

For me it’s right to open this dialog to let the user choose the printer to use, otherwise a user with multiple printers will not know where to find the printed documents :wink:

Yes of course - the question is what direct print is meaning :slight_smile:

I think a good idea would be let “personalize” the printing button to let you choose an specific printer and some specific printing parameters. At the moment I use the email button (on desktop client) to do this. Because when you have to print always the same report and you need to “simplify” the operation a direct printing button it’s necessary, and in Linux environment the direct print button doesn’t work. In order to do this I have set the email button in this way:

lp -d Zebra_Technologies_ZTC_S4M-200dpi_ZPL ${attachment}

Cheers!

That’s a workaround - so this seems to be an issue that should discussed.

Agreee, this should be reported and find a fix for it.

Just in case somebody finds it useful we created a printer module that allows defining where each report should be sent. You can choose to send it to the client (the default behaviour) or to any of the printers of the CUPS server.

Unfortunately it requires a hook on reports but that was already discussed and rejected.

1 Like

Same as GTK client, the user need do some extra configuration at the browser (plugin, kiosk, … depends the browser configuration).

At the moment, I think the simplest solution is open the report in a new window window.open(), (when a report is pdf or txt and has “direct print” option a true) and the user do the print option (crt+p).

From Per user list view definition , after reading source code from
kalenis_frontend
, you could see that use a custom “direct print”.

Hi,
Yes, we implemented this as a “temporary” fix, opening the print dialog. We try not to depend on specific browser settings or plugins, so we take kind of a “standard” way. In my opinion, there are cases when this is far from ideal (Example: if you are printing labels, you just want them to go straight to the printer and the extra step on the print dialog was not well received)

We briefly try this with no success and getting different behaviors on browsers (between Chrome and Firefox for example).

For me this sounds like a proper solution.
It will be great if somebody can propose an implementation for sao.

I think for this casses the best solution is to send an email notification (if the printer supports printing from email) or some of the options that were already suggested.

Have you seen the script above? This little print server is a very simple way to print something without any dialog. I use it on a packing table: package packed - label will print. And also a delivery note on a A4-printer. With this you can print different documents in different formats on different printers triggered by only one action.

FYI, we’re successfully using https://qz.io for direct printing from the browser. It is a plugin that works in several browsers.

Maybe we could add support for it in sao.

I would not like to embed java library in sao.

Indeed I think the simplest solution would be to use such way: javascript - Silent print an embedded PDF - Stack Overflow
The <embed/> and Window.print() are compatible on a large set of browsers.

Well, it is up to the user whether she wants to install the plugin or not. Sao does not need to add java, just a few lines of code to check if the plugin is available and send the report.

There’s a couple of things the plugin provides which this solution doesn’t:

  • Printing reports in other formats other than PDF (frequently needed for label printers)
  • Choosing to which printer you want to print to

I do not see the point to add such code if it requires anyway a customization.