php怎么调用指定的打印机

php怎么调用指定的打印机,第1张

php生成的是网页吧,然后用ie浏览,在ie上有个打印按钮,可以选择打印机

但ie不是你用php写的,是微软写的

你怎么控制一个微软写的软件,并使用它选择打印机?除非他提供了接口

微软是否提供了接口,应该没有,否则早有人回帖了

但还有一个可能,当你改变本机 打印机的首选项时,有可能记录在注册表里面。如果是这样,那就直接改变注册表,就相当于选择了打印机

但是你想,当你浏览一个网页,它会修改你的注册表,这让人放不放心,算不算病毒,会不会被杀毒软件屏蔽?或者根本通不过ie默认的安全选项

最终结局就是,b/s方式不要想控制客户的硬件

但我还是要打印,在当前,只有让客户安装打印控件,这样才可能让客户自定义打印机相关

还有一种想法,不用客户端控制来打印,把打印要求提交到服务器,让服务器选择打印机,没有用过,你不如研究一下?

另外php最多只能控制服务器的硬件,想控制客户机最多只能用js

对客户机某些打印选项的注册表 *** 作,下面有js的例子用法,很久以前的,仅做参考

<script>

var hkey_root,hkey_path,hkey_key

hkey_root="HKEY_CURRENT_USER"

hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"

//设置网页打印的页眉页脚为空

function pagesetup_null(){

try{

var RegWsh = new ActiveXObject("WScript.Shell")

hkey_key="header"

RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")

hkey_key="footer"

RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")

hkey_key="margin_left"

RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"0.2")

hkey_key="margin_bottom"

RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"0.2")

hkey_key="margin_right"

RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"0.2")

hkey_key="margin_top"

RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"0.2")

}catch(e){}

}

//设置网页打印的页眉页脚为默认值

function pagesetup_default(){

try{

var RegWsh = new ActiveXObject("WScript.Shell")

hkey_key="header"

RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P")

hkey_key="footer"

RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&u&b&d")

}catch(e){}

}

</script>

打印分页

<p style="page-break-after:always">page1</p>

<p style="page-break-after:always">page2</p>

你的打印是不是编程语言里面说的打印,例如basic语言的print语句,如果是的话,在PHP里面使用echo语句打印内容,例如:

echo '<table border=1><tr><td>1<td>2</table>'

如果你是希望程序运行后在打印机上打印输出内容,那可能比较复杂,而且不是PHP的强项,需要编写许多查找打印机的代码,简单的做法是把数据送我特殊设备,可以使用file_put_contents函数,例如:

file_put_contents('PRN:', 'print test')

分二种情况:

第一种打印到屏上,超简单就用

<?

echo ("PHP代码段打钱中...")

?>

第二种,打印到打印机,这种大多都是用JS方法:

1【<a href='javascript:window.print()'>打印此页</a>】

2.若为按钮 <input type="submit" value="打印" onClick="javascript:window.print()"/>

3.

Javascript代码:

<script language="javascript" type="text/javascript">

function printsetup(){wb.execwb(8,1)}

function printpreview(){wb.execwb(7,1)}

function printit(){wb.execwb(6,6)}

function printclose(){wb.execwb(45,1)}

//WebBrowser.ExecWB(1,1) 打开

//Web.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口

//Web.ExecWB(4,1) 保存网页

//Web.ExecWB(6,1) 打印

//Web.ExecWB(7,1) 打印预览

//Web.ExecWB(8,1) 打印页面设置

//Web.ExecWB(10,1) 查看页面属性

//Web.ExecWB(15,1) 好像是撤销,有待确认

//Web.ExecWB(17,1) 全选

//Web.ExecWB(22,1) 刷新

//Web.ExecWB(45,1) 关闭窗体无提示

</script>

CSS代码:

<style media="print" type="text/css">

.Noprint{display:none}

.NextPage{page-break-before:always}

</style>

网页代码:

<object id="wb" height="0" "width=0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" name="wb"></object>

<div class="Noprint" style="text-align: rightborder: 1px solid #99BCFCmargin:0px 5px 0px 5pxpadding:2px 5px 2px 5pxbackground-color: #EBF1FA">

<input type="button" onclick="javascript:printsetup()" name="button2" id="button2" value="页面设置"/>

<input type="button" onclick="javascript:printpreview()" name="button3" id="button3" value="打印预览"/>

<input type="button" onclick="javascript:printit()" name="button4" id="button4" value="打印"/>

<input type="button" onclick="javascript:printclose()" name="button" id="button" value="关闭"/>

</div>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12196376.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存