views:

3580

answers:

8

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.

A: 

For security reason this cannot be done. Imagine how many compagnies would just go and print advertisment without your consent.

You won't be able to bypass the security layers of a regular browser. Maybe you could write a firefox extensions, or run your webapp in an HTA if you're on windows...

poulejapon
Well, I've already done it, so saying it can't be done is wrong.
Bill
A: 

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?

Rob Cooper
+1  A: 

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.

Christopher Mahan
+2  A: 

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.

Espo
A: 

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.

Vaibhav
No, it's an internal application in the sense that it's available to the general public, but it will be at places like various retail chains, etc.
Bill
+3  A: 

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

A: 

Can Firefox be configure to follow the DEFAULT PRINTER and ITS PRINTING DEFAULTS? Particularly the PAPER SIZE.

Dominic Flandez
A: 

You can try CLPrint http://commandlinepdf.com Print all your PDF documents to any printer you have. You can define the DPI, print range, color mode and many more all from your command prompt.