Printing - Silent Print From Browser - Stack Overflow

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

08/06/2022 16:33 printing - Silent Print From Browser - Stack Overflow

Silent Print From Browser [duplicate]


Asked
6 years, 2 months ago Modified
2 years, 3 months ago Viewed
14k times

This question already has answers here:

4 "Silent" Printing in a Web Application


(11 answers)

Closed 2 years ago.

I have researched so much in the last few days and have given my enough head in that issue.
4
What I'm trying to achieve is to print directly from web using a print button. I don't want to
browser print popup to appear. There will be 2 printers attached to my web application and I
want the printer selection automatically.

I know that it is not possible with PHP or without any browser extension or active x plugin.

I also thought a solution to send the print request using web sockets while a java socket client
application installation over the user system.

Please suggest me any time saving solution to my problem

browser printing

Share Improve this question edited Feb 15, 2020 at 19:28 asked Mar 28, 2016 at 15:30
Follow Dharman ♦ Faizan Afzal
26.9k 21 73 125 413 2 11 19

1 You're not going to be able to override the print functionality of a client browser. PHP/Java will have
nothing to do with it.
– kevingreen
Mar 28, 2016 at 15:39

The idea is to let java client application handle the print request
–  Faizan Afzal
Mar 28, 2016 at 15:40

You want to build a Java web client, that calls a web site and will print the page?
– kevingreen
Mar 28,
2016 at 15:41

I've looked into the chrome extensions, fire fox addon, a php web client tool which install a little
application on the client pc and then you can install from the web.. But none of the solution seems
reliable to me. I've an idea in my mind to build a PHP Socket Server and an build a Java Socket Client..
The Client will establish a connection with the Server and whenever Server will get the print request, it
will pass the print data to Java Client where the entire print functionality will be handled
–  Faizan Afzal
Mar 28, 2016 at 15:54

What's the point of a socket server to print? You can render HTML to a printable format pretty easy in
Java. You just need 1 application to call it.
– kevingreen
Mar 28, 2016 at 15:57

Sorted by:
Reset to default
2 Join Stack Overflow to find the best answer to your technical question, help others
Answers Sign up
answer theirs. Date modified (newest first)

https://stackoverflow.com/questions/36265503/silent-print-from-browser 1/3
08/06/2022 16:33 printing - Silent Print From Browser - Stack Overflow

The short of it is, dealing with HTTPS over a socket connection is tricky because of mixed
content restrictions and changing SSL standards so authoring this from scratch to work on all
2 platforms can be daunting.

I also thought a solution to send the print request using web sockets while a java
socket client application installation over the user system.

This is exactly how QZ Tray works.

qz.websocket.connect().then(function() {
return qz.printers.find("zebra"); // Pass the printer name into the
next Promise
}).then(function(printer) {
var config = qz.configs.create(printer); // Create a default config for the
found printer
var data = ['^XA^FO50,50^ADN,36,20^FDRAW ZPL EXAMPLE^FS^XZ']; // Raw ZPL
return qz.print(config, data);
}).catch(function(e) { console.error(e); }

The above example is specific to raw printing, but the app will work for other formats as well
(HTML, PDF, images)

Project page:
https://github.com/qzind/tray

Full disclaimer.... as the author of the above plugin, I find it fair to mention that PrintNode
does a near identical task. Both plugins are open source but backed by commercial services
which support them.

Project page:
https://github.com/PrintNode

Share Improve this answer Follow answered Jan 11, 2020 at 18:22
tresf
5,377 5 34 92

I've looked into the chrome extensions, fire fox addon

- Faizan Afzal Mar 28 at 15:54


9

In the above comment, you mentioned that you've looked into Chrome extensions and
FireFox addons, however there is already the functionality built into these browsers to disable
the print dialog.

If the web application you're making will be run in a controlled environment (where you
manage which browsers access it and how they're configured), you can fairly easily do this.

Chrome

Firstly, go to chrome://settings/ and change your home page to the web application. Next,
Join Stack Overflow to find the best answer to your technical question, help others
make a shortcut for the Chrome browser on your desktop then right click on it toSign
open
up the
answer theirs.

https://stackoverflow.com/questions/36265503/silent-print-from-browser 2/3
08/06/2022 16:33 printing - Silent Print From Browser - Stack Overflow

properties window. In the 'Target' input field, add --kiosk --kiosk-printing to the end of
the location. Apply the changes, close all Chrome windows and click on the shortcut. This
should put you in full screen (kiosk mode) and when you attempt t print, it should
automatically print on the default printer without a pop-up window being displayed.

FireFox

On FireFox, go to about:config and agree to any warning messages. Then, right click
somewhere on the page and create a " New -> Boolean ". It will prompt you for a name and a
state. For the name, enter print.always_print_silent and for the state, set it to true. Then
you will need to save changes and restart any FireFox windows you have open. If you attempt
to print something, it will no longer require the pop-up window to be displayed and will
automatically print on the default printer.

With either of these browsers configured in this way, you can use the standard
window.print(); JavaScript method to print without needing any kind of server-side
interaction.

Batch Files?

If you'd like an easier way to do these, you can use these two command prompt scripts which
will automatically configure and/or run them to suit your needs:

Chrome:

cd Program Files (x86)\Google\Chrome\Application


chrome.exe --kiosk --kiosk-printing

FireFox:

FOR /D %%G in ("%APPDATA%\Mozilla\Firefox\Profiles\*.default") DO SET prof=%%G


cd %prof%
echo user_pref("print.always_print_silent", true);>>prefs.js
cd \..
cd Program Files (x86)\Mozilla Firefox
firefox.exe

Share Improve this answer Follow edited Jun 14, 2016 at 11:09 answered Apr 13, 2016 at 15:38
Nathangrad
1,386 8 24

Join Stack Overflow to find the best answer to your technical question, help others
Sign up
answer theirs.

https://stackoverflow.com/questions/36265503/silent-print-from-browser 3/3

You might also like