使用php_printer.dll打印pdf文件

时间:2015-05-27 08:18:30

标签: php

我想使用php打印pdf文件到默认打印机但不打印文件并将空白页作为输出。

$handle = printer_open("\\\\192.168.1.30\Brother MFC-J430W Printer");

printer_start_doc($handle, "PET PASS");

printer_start_page($handle);

$filename = "test.txt";

$fhandle=fopen($filename, 'r');
$contents = fread($fhandle, filesize($filename));
fclose($fhandle);

printer_set_option($handle, PRINTER_MODE, "RAW");
printer_write($handle,$contents);

printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);

感谢。

1 个答案:

答案 0 :(得分:0)

以这种方式尝试:

<?php 
$printer = "\\\\Pserver.php.net\\printername"); 
if($ph = printer_open($printer)) 
{ 
   // Get file contents 
   $fh = fopen("filename.ext", "rb"); 
   $content = fread($fh, filesize("filename.ext")); 
   fclose($fh); 

   // Set print mode to RAW and send PDF to printer 
   printer_set_option($ph, PRINTER_MODE, "RAW"); 
   printer_write($ph, $content); 
   printer_close($ph); 
} 
else "Couldn't connect..."; 
?>