Select a printer and silently print

54,139

Solution 1

Maybe you could setup your printers with Google Clound Print then use the cloud printing API to silently submit jobs to them. It looks like you can specify the printer id when you submit the job. You might need to use something like html2canvas to rasterize the webpage.

Solution 2

If you are in an environment that you know, and in wich you have enough privileges (i suppose, since you know the printer you want to use) you can try to change it through the command line. For this, you should call

@RunDLL32.EXE printui.dll,PrintUIEntry /y /n "Printer name"

The printer name has to be the value displayed in the control panel.

For calling command line from javascript, if you have the proper ActiveX controls enabled, you can use:

var run=new ActiveXObject('WSCRIPT.Shell').Run("commands to run");

also, you can try with shell.application ShellExecute

 var objShell = new ActiveXObject("shell.application");
objShell.ShellExecute("cmd.exe", 'RunDLL32.EXE printui.dll,PrintUIEntry /y /n "Printer name"', "C:\\WINDOWS\\system32", "open", 1);

For more information you can go to http://msdn.microsoft.com/en-us/library/windows/desktop/gg537745(v=vs.85).aspx

I havent tested it, so good luck!

Solution 3

I have searched for an answer but it looks like there is no way to set a printer programatically. Therefore my probably complicated solution:

Create a command line application which can switch the default printer of the operating system. Maybe an application which is capable of disabling and enabling a printer. If you are on Windows a .NET application could probably do this. If on Linux there should be a command line interface for printer management (I don't know for sure).

Now make for example a PHP, asp.net or ruby etc. page which is able to call the printer enable/disable program.

If this is working you can use Javascript calls to first print to printer one and after the switch to printer two. However there some disadvantages:

  • If printer one is printing a document you can not switch to printer two, since this will disable printer one. So somehow you should time how long a common job takes.
  • There is a lot of overhead in this solution. You need to made extra calls for the switch between printers
  • Maintainability is absolutely not optimal since you need to maintain the printer switch program and the webservice.

I hope for you someone comes up with a better solution, but I wanted to at least share my thoughts. Maybe they help you in solving your problem.

Share:
54,139
Admin
Author by

Admin

Updated on August 13, 2021

Comments

  • Admin
    Admin almost 3 years

    This answer shows how to enable silent printing in Google Chrome. However, I have two web pages which have to be silently printed using two different printers without further user interaction. Is there a way to select a printer automatically before calling window.print()? I don’t mind writing a Chrome Extension if really necessary.