Printing directly to a network printer using php

I cannot print the page on a network printer using php.
But it works if it is a local printer. I installed php_printer.dll and is included in php.ini The following is the code:

//$handle = printer_open("Send To OneNote 2007"); ///This Works $handle = printer_open('\\\\192.168.0.8\\Canon MF4320-4350'); printer_set_option($handle, PRINTER_MODE, "RAW"); printer_write($handle, "TEXT To print"); printer_close($handle); 

Error displayed here

Warning: printer_write () [function.printer-write]: failed to allocate printerjob [5] in E: \ Server \ xampp \ htdocs \ Kiosk \ Admin \ print.php on line 16

+4
source share
3 answers

If you use the PHP command line (CLI), printing to network printers will work. By the way, your $ addr is correct.

The problem is PHP when you combine it with Apache. On Windows, your php scripts will run under the SYSTEM user account. Due to security issues, all network resources are not displayed in SYSTEM.

To fix this problem, create a new user with administrator privileges (or at least with the visibility of a network resource). On Windows, if you start Apache as a service, click the SERVICE button in Apache Service Monitor. In Apache 2.2, right-click on properties. On the LOGIN tab, change the user from SYSTEM to the newly created user account. Restart Apache. Now you can run your PHP script to print on network printers.

+7
source

Try using "s with 4" or with 3. eg:

 $handle = printer_open("\\\\192.168.0.8\\Canon MF4320-4350"); // or $handle = printer_open('\\\192.168.0.8\Canon MF4320-4350'); 

Also, try using a domain name rather than IP (for example, computer-name or full.address.example.com ).

+1
source

Just by looking at this line, it feels as if it could be caused by a backslash failure.

Debugging tip: specify the network address in a variable, and not directly in printer_open() . Then use print() or similar to display the value.

 <?php $addr = '\\\\192.168.0.8\\Canon MF4320-4350'; print $addr; printer_open($addr); ... ?> 

This will allow you to see the meaning of the string used, which can help you understand what is going wrong, and, more importantly, help you understand how to fix it.

Hope this helps.

0
source

Source: https://habr.com/ru/post/1339171/


All Articles