6

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

Community
  • 1
  • 1
sipdorus
  • 963
  • 1
  • 12
  • 28
  • If this is for an internal company project, you could create a custom protocol that invokes some .NET code to open a specific print dialog, or if on mac, a custom protocol that invokes an AppleScript to do so. Otherwise, no, there's no generalized way to achieve this. – Patrick Roberts Feb 19 '18 at 20:32
  • You are using PHP, so yeah, you could achieve that, but not with JavaScript (unless you are using node.js) – Ravenous Feb 26 '18 at 18:46

3 Answers3

6

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.

Ali Soltani
  • 9,589
  • 5
  • 30
  • 55
1

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

Jim Yarbro
  • 2,063
  • 15
  • 21
0

best way is using js print setup extension on firefox. But the extension dos not support over firefox 56. So you have to donwload max firefox 56 version, disconnect internet (automatically updates to firefox 58), setup firefox, disable auto update then re-connect internet. By this way you can use a specific printer without select printer dialog.

Thanks for other replies.

sipdorus
  • 963
  • 1
  • 12
  • 28