使用 printer_write() 函数直接从 PHP 打印

Printing directly from PHP using printer_write() function

我发现直接从 PHP 打印的代码:

$printer = "cups-pdf";
$ph = printer_open($printer);
if ($ph) {
    $content = "Hello World...";
    printer_set_option($ph, PRINTER_MODE, "RAW");
    printer_write($ph, $content);
    printer_close($ph);
} else {
    echo "Couldn't connect...";
}

我正在尝试在 Ubuntu 14.04 LTS 上使用 XAMPP 对其进行测试。但它给了我一个错误:

Fatal error: Call to undefined function printer_open() in /opt/lampp/htdocs/test/test.php on line 4`

我该如何解决?

目前无法安装 Printer extension as it is Windows-only. There is no config*.m4(for Unix-like systems) file in the source,只能安装 config.w32(适用于 Windows)。

PECL包说明里也写着:

Printer allows drawing (text, lines, ellipse, paging, etc.) and spool controlling operation using a printer device on Windows.