5
votes

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

3
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
You are using PHP, so yeah, you could achieve that, but not with JavaScript (unless you are using node.js) - Ravenous

3 Answers

6
votes

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.

1
votes

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

0
votes

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.