padamghimire75@gmail.com's avatar

How to fetch list of printers in windows?

I am using laravel 5.8 and PHP 7.3.31
How to list out the printers that are connect to the system?
0 likes
1 reply
shaungbhone's avatar
Level 28

Here, what I found.

<?php
// Get the list of printers
if (PHP_OS_FAMILY === 'Windows') {
    exec('wmic printer list brief', $output);
} else {
    exec('lpstat -p', $output);
}

// Display the list in a table
echo "<table>";
echo "<tr><th>Printer Name</th><th>Location</th><th>Status</th></tr>";
foreach ($output as $line) {
    $printer = explode(',', $line);
    echo "<tr><td>{$printer[0]}</td><td>{$printer[1]}</td><td>{$printer[2]}</td></tr>";
}
echo "</table>";
?>

2 likes

Please or to participate in this conversation.