Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set browser printer for specific page

I'm coding a web based software. I print barcodes.

There are 2 printers at the PC, so user always has to select barcode printer for printing barcode and laser printer for printing reports.

Is there any way to set a printer for a page. (From browser settings or via javascript)

For example :

www.example.com/barcodeprint.php ----> Barcode printer

www.example.com/reportprint.php ----> Laser printer

Thanks

like image 492
sipdorus Avatar asked Feb 16 '18 16:02

sipdorus


People also ask

How do I print an exact Web page?

Open the web page. 2. Press Ctrl + A 3. Right click on the page and left click on “Print” 4.


2 Answers

JavaScript will not allow you to override the default page setup of the client's browser, because the browser protects the hardware and operating system by sandboxing the scripts to avoid anything malicious.

But your issue is similar this question and maybe you could setup your printers with Google Cloud Print then use it's API to do it.

like image 81
Ali Soltani Avatar answered Oct 17 '22 11:10

Ali Soltani


No, unfortunately that’s a machine specific configuration. Even users can have individual configurations of printers.

However there is a little hope. You can execute JS with printing specific event handlers to pop up instructions for the user to select a specific printer. This will help push them to select the correct one.

https://developer.mozilla.org/en-US/docs/Web/Guide/Printing

like image 39
Jim Yarbro Avatar answered Oct 17 '22 09:10

Jim Yarbro