在没有 Windows 打印对话框的情况下使用 php (javascript) 在本地打印页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4077832/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Print a page on local using php (javascript) without Windows print dialog box
提问by eMRe
I am developping an intranet for a shop. I need to print a receipt by clicking a submit button on php page. I do not want to see Windows print dialog box.
我正在为一家商店开发内联网。我需要通过单击 php 页面上的提交按钮来打印收据。我不想看到 Windows 打印对话框。
how can I do this. I need some advise
我怎样才能做到这一点。我需要一些建议
I will use Windows XP, I have full control of the system which this application will be running, Any application/plugin/exploits etc can be installed or used to help with removing the print dialog box.
我将使用 Windows XP,我可以完全控制此应用程序将运行的系统,可以安装任何应用程序/插件/漏洞等,或用于帮助删除打印对话框。
Regards
问候
回答by CommentLuv
I do this with my shop order system written in PHP and it uses a print dialog via jquery. you can bypass the firefox print dialog by using the about:config page.
我使用用 PHP 编写的商店订单系统执行此操作,它通过 jquery 使用打印对话框。您可以使用 about:config 页面绕过 firefox 打印对话框。
- Open firefox and put about:configin the address bar and press enter (you will need to click the button that shows to say you know what you're doing)
- Type print.always_print_silentin the filter box at the top
If you have an entry already there and it is set to false just right click it and choose 'toggle' to set it to true.
If there is no entry there already then follow on...
- right click the screen and choose New->boolean
- enter print.always_print_silentas the preference name when asked and press enter
- set boolean value to trueand press enter
- 打开 firefox 并将about:config放在地址栏中,然后按 Enter(您需要单击显示的按钮以说明您知道自己在做什么)
- 在顶部的过滤器框中键入print.always_print_silent如果您已经有一个条目并且它被设置为 false 只需右键单击它并选择“toggle”将其设置为 true。如果那里没有条目,那么继续......
- 右键单击屏幕并选择 New->boolean
- 询问时输入print.always_print_silent作为首选项名称,然后按 Enter
- 将布尔值设置为true并按 Enter
That's it, you will no longer see the dialog box when you print. Beware though, it will try to print to the last printer you used when you had the dialog box open. If you ever need to change it then you will need to toggle the value for print.always_print_silent by following the above steps.
就是这样,打印时您将不再看到对话框。但请注意,当您打开对话框时,它会尝试打印到您使用的最后一台打印机。如果您需要更改它,则需要按照上述步骤切换 print.always_print_silent 的值。
回答by Nick Craver
You can't bypass the print dialog, advertisers would be printing out flyers to your printer if this was possible.
您无法绕过打印对话框,如果可能,广告商会将传单打印到您的打印机上。
回答by Harmen
Javascript can only trigger the print function with window.print()
, but cannot change the way the browser works.
Javascript 只能用 触发打印功能window.print()
,不能改变浏览器的工作方式。
回答by Z. Zlatev
You can't simply pass the pring dialog. I'm not aware of such functionality but could be possible using JAVA.
您不能简单地传递 pring 对话框。我不知道这样的功能,但可以使用 JAVA。
回答by TheGrandWazoo
Assuming you have the printer attached to the server, you can render the receipt/document to a PDF file, write it to a temporary directory and use the 'shell_exec' function to print it. The shell_exec function executes commands from the command line. Since Windows has something called a command line, it can be usefull.
假设您将打印机连接到服务器,您可以将收据/文档呈现为 PDF 文件,将其写入临时目录并使用“ shell_exec”函数打印它。shell_exec 函数从命令行执行命令。因为 Windows 有一个叫做命令行的东西,它很有用。
Be aware that you need a program or batch file installed that can print a PDF from the command line. Such batch file can be found here.
请注意,您需要安装可以从命令行打印 PDF 的程序或批处理文件。可以在此处找到此类批处理文件。