0

How to get all device printer names connected to the system in network using php? I tried the following code.

<?php
$getprt=printer_list(PRINTER_ENUM_LOCAL| PRINTER_ENUM_SHARED );
$printers = serialize($getprt);
$printers=unserialize($printers);
//print_r($printers);
echo '<select name="printers">';
foreach ($printers as $PrintDest)
    echo "<option value=".$PrintDest["NAME"].">".explode(",",$PrintDest["DESCRIPTION"])[1]."</option>";
echo '</select>';
?>

I got a fatal error: Call to undefined function printer_list() in C:\xampp\htdocs\test\getprinter.php on line 2

SwR
  • 612
  • 1
  • 8
  • 21

3 Answers3

-1

You can follow this tutorial :

http://basic-programming-tips.blogspot.ch/2013/07/php-phpprinterdll-installation-and.html

Goto Xammp Home directory (ex C:\Xampp)

  1. Then open php folder

  2. Then open php.ini file.

  3. Find ;extension=php_printer.dll

  4. Then Remove ";"

  5. Done

This restart your server and it should works.

PS : If you don't have php_printer.dll => https://github.com/maryo/php-5.5-windows-extensions/tree/master/php_printer-0.1.0-dev-5.5-vc11-x86

David Ansermot
  • 6,052
  • 8
  • 47
  • 82
  • Actually,<;extension=php_printer.dll > is missing in php.ini – SwR May 17 '16 at 10:49
  • So you have to search on google to download and install it before adding to php.ini https://github.com/maryo/php-5.5-windows-extensions/tree/master/php_printer-0.1.0-dev-5.5-vc11-x86 – David Ansermot May 17 '16 at 10:54
-1

I solved my issue.Problem was with my php_printer.dll.Once I copied right version of php_printer.dll compatible with PHP Version 5.6.14,started working.

php_printer.dll copied into ext folder.and edited php.ini.

SwR
  • 612
  • 1
  • 8
  • 21
-1

You can get list of connected printers to your system by using exec().

    if (PHP_OS_FAMILY === 'Windows') {
        exec('wmic printer list brief', $printers_arr);
    }else{
        exec('lpstat -p', $printers_arr);
    }
    return $printers_arr;