我尝试直接用php库php_printer.dll打印,我的问题是我的打印机打印奇怪的单词而不是PDF文件。
这是我的代码:
<?php
$printer = ("Epson Printer");
if($ph = printer_open($printer))
{
$file = file_get_contents('receipt.pdf', FILE_USE_INCLUDE_PATH);
printer_write($ph, $file);
printer_close($ph);
}
else "Couldn't connect...";
?>更新
现在,我尝试在Windows 7上使用这段代码,但不打印开始:
shell_exec( 'print /d:EPSON MFC-J265W c:\file.txt');发布于 2012-10-24 08:11:22
好吧..。您的内容由所有标签组成,您将向打印机提供text类型输出。
当然,它会像那样印刷。
如果您只想用文本Write a test 20012-10-24直接打印,那么您可能需要在另一个file_get_contents文件中创建它,用file_get_contents读取输出,然后用收到的结果进行打印。
现在打印PDF文件是一个完全不同的问题。您可以通过shell执行打印它:
shell_exec( 'lpr /path/to/file/filename.pdf' );或者使用找到的这里类:
require_once( 'PrintIPP.php' );
$ipp = new PrintIPP();
$ipp->setHost( 'localhost' );
$ipp->setPrinterURI( '/printers/epson' );
$ipp->setData( '/path/to/file/filename.pdf' );
$ipp->printJob();https://stackoverflow.com/questions/13045153
复制相似问题