"Silent" Printing in a Web Application

Viewed 77926

I'm working on a web application that needs to prints silently -- that is without user involvement. What's the best way to accomplish this? It doesn't like it can be done with strictly with Javascript, nor Flash and/or AIR. The closest I've seen involves a Java applet.

I can understand why it would a Bad Idea for just any website to be able to do this. This specific instance is for an internal application, and it's perfectly acceptable if the user needs to add the URL to a trusted site list, install an addon, etc.

11 Answers

Here’s what you need to do to enable Firefox immediately print without showing the print preferences dialog box.

  1. Type about:config at Firefox’s location bar and hit Enter.

  2. Right click at anywhere on the page and select New > Boolean

  3. Enter the preference name as print.always_print_silent and click OK.


I found that somewhere and it helped me

Here are two code samples you can try:

1:

<script>
function Print() {
  alert ("THUD.. another tree bites the dust!")
  if (document.layers)
  {
    window.print();
  }
  else if (document.all)
  {
    WebBrowser1.ExecWB(6, 1);
    //use 6, 1 to prompt the print dialog or 6, 6 to omit it
    //some websites also indicate that 6,2 should be used to omit the box
    WebBrowser1.outerHTML = "";
  }
}
</script>
<object ID="WebBrowser1" WIDTH="0" HEIGHT="0"
CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
</object>

2:

if (navigator.appName == "Microsoft Internet Explorer")
{ 
  var PrintCommand = '<object ID="PrintCommandObject" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
  document.body.insertAdjacentHTML('beforeEnd', PrintCommand); 
  PrintCommandObject.ExecWB(6, -1); PrintCommandObject.outerHTML = ""; 
} 
else { 
  window.print();
} 

You may need to add the site/page you are testing on to you local intranet zone.

I wrote a python tsr that polled the server every so often (it pulled its polling frequency from the server) and would print out to label printer. Was relatively nice.

Once written in python, I used py2exe on it, then inno setup compiler, then put on intranet and had user install it.

It was not great, but it worked. Users would launch it in the morning, and the program would receive the kill switch from the server at night.

I have to be honest, I am kinda thinking out loud here.. But could it not be done with an applet or some sort (be it Java or whatever) that is given trusted permissions (such as that within the Intranet zone) or something?

May be worth investigating what permissions can be given to each zone?

Following a Google, I think you definately have a challenge, so far most of the articles I have seen involve printing to printers connected to the server.

If its internal, would it be possible to route printing from the server to department/user printers or something?

If it is just an internal application, then you can avoid printing from the browser, and send a printout directly from the server to the nearest printer to the user.

Related