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.

- 1
- 1
-
3if one of the docs to be printed is plain text, you can open it with a simple batch file wrapper that opens notepad and prints the text. you would popup a custom mime-type dataURL and associate your batch file with that type. you can then print text using the dataURL and html using window.print(). the other answer is "no". – dandavis Dec 03 '13 at 18:54
5 Answers
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.

- 1,661
- 13
- 33
-
-
5UPDATE: Google Cloud Print will no longer be supported as of December 31, 2020. Please see the support article for help migrating. https://support.google.com/chrome/a/answer/9633006 – Lucas Argate Apr 08 '20 at 12:05
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!

- 10,828
- 3
- 41
- 60
-
your solution looks exotic, going to try it out. Do you by any chance know a way i could mimic the printer setup. At the moment i don't have access to the actual printer (it will be badge printer, a zebra or evolis) – alex Jan 14 '16 at 16:43
-
Just tested and it works, however it works in IE only and requires allowing to "Initialize and script active x controls is not marked safe for scripting" in IE Security settings, see [this answer](http://stackoverflow.com/a/16801148/3549014) for more details. – Gyrocode.com May 17 '17 at 15:40
I ended up writing a server in F# and communicating with that through a WebSocket.
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.

- 9,933
- 10
- 55
- 91
-
this solution has two major problems ( I hope we can overcome ): 1- First: the server of php, asp, ruby or whatever should be on the same machine, if it is a client machine, and you called the javascript, what can it do? 2-Second and equally important: if you are able (via javascript) to change default printer of the SYSTEM, this does not change chrome's default printer, as it is fixed to the last used printer......... I have a solution to change system setting via javascript, although complicated, but can work efficiently, the problem now is : where can I change chrome's default printer??!! – Amro May 09 '14 at 00:11
If you're doing this for a product or webapp that will run in an environment where there are printers etc. A better solution to just giving clients a webappp to run might be to wrap your webapp with a desktop application using Chromium Embedded Framework. Like Chromely (kind of like Electron, but lighter), EdgeSharp or CEFSharp etc.
Using this technique, you can write code that can actually enumerate printers on the network and talk to hardware while still running your webapp and you can expose new JS api's you build in the desktop app to your web application.
Then to make it smart, you can have your webapp work in both environments, running in the desktop app, or directly in a browser. Where it would have advanced extended features running in the desktop application.
Then you can deploy said application a plethora of ways. For example, Windows 10+ you can have a private windows Store for your company and you can deploy the application to your private windows store where it can be installed via the Private Windows Store which you can setup with Group Policies on Windows.
Or you could have a private npm repo and script the install/update of your application. Even old school techniques like Microsoft Click Once installs, and on and on.
But the most power you can possibly give your web application is to give it a custom browser to run on and with Chromium Embedded Framework it's so easy.
In C# you can spin up a simple Chrome wrapper in less than 60 seconds.
Using .Net 6+ and EdgeSharp for example, you could get this to be cross platform on Linux, Windows, and MacOsx, and also port it to Xamarin and IOS pretty easily so that you can have this power on phones, pc's, mac's, and tablets.

- 5,178
- 32
- 42