之前见过很多都是使用js来进行打印的,这次分享个php的,这里只说下php的方法。需要的同学可以自己动手实现一下哦!
遇到的问题:
用php语言开发的商城系统,需要用到批量打印发货单、快递单的功能。这个该怎么实现。
目前看到的办法就是使用浏览器自带的打印功能打印网页,将内容显示在网页上 然后打印,但是这样怎么保证打印出来的页面合理?或者还有什么办法?
Windows:
PHP有一个叫Printer的Windows扩展,使用win32api调用系统打印机服务。
可以打印格式化的文档、报表,还可以画一些简单的图形,打印图片。
样例代码:
<?php
/* get the sample text */
$lipsum = file_get_contents('lipsum.txt');
/* open a connection to the printer */
$printer = printer_open("Lexmark X850e XL V");
/* write the text to the print job */
printer_write($printer, $lipsum);
/* close the connection */
printer_close($printer);
?>
资料:http://phpstarter.net/2010/05/send-print-jobs-directly-from-php/
Unix/Linux:
可以使用system()
函数调用lpr
工具连接打印服务器来完成打印工作
<?php
system('lpr -P "Hp Deskjet" document.pdf');
?>
资料:http://linux.about.com/library/cmd/blcmdl1_lpr.htm
PHP生成PDF文件的扩展:http://www.php.net/manual/en/book.pdf.php
看完如果如果对你有帮助,顺手点下
点原文查看更多相关例子!