带有html输出的PHP打印机函数

aiqt4smr  于 2023-01-16  发布在  PHP
关注(0)|答案(1)|浏览(130)
<?php 
$printer = "PrinterName"; 
if($ph = printer_open($printer)) 
{ 

   $fh = fopen("file.txt", "rb"); 
   $content = fread($fh, filesize("file.txt")); 
   fclose($fh); 

   printer_set_option($ph, PRINTER_MODE, "RAW"); 
   printer_write($ph, $content); 
   printer_close($ph); 
} 

?>

这是我用PHP选择打印机打印一个.txt格式文件的代码。我应该在哪里修改才能用HTML输出打印一个.php页面?有什么建议吗?请帮助我

ogsagwnx

ogsagwnx1#

要打印任何页面,请按如下所示修改代码

$page = "http://your_domain_name/filename.php";
print_page($page);

function print_page($page)
{
    $printer = "PrinterName"); 
    if($ph = printer_open($printer)) 
    { 

       $content = get_file_contents($page); 

       printer_set_option($ph, PRINTER_MODE, "RAW"); 
       printer_write($ph, $content); 
       printer_close($ph); 
    } 
}

相关问题