我正在尝试设置 CLI PHP 应用程序以将一组网页打印到默认或指定的打印机.我在 Windows 7 机器上,PHP 5.2.11 在 CLI 中运行.为了测试打印功能,我加载了 PHP_printer.dll 并打印到 Onenote,这是一个打印到文件选项,使用 PRINTER_ENUM_LOCAL 中给出的确切打印机名称.
更新:这是最新的代码:
I'm trying to set up a CLI PHP application to print a set of web pages to a default or specified printer. I'm on a Windows 7 machine with PHP 5.2.11 running in a CLI. To test the print functionality I've loaded PHP_printer.dll and I'm printing to Onenote, a print to file option, using the exact printer name given in PRINTER_ENUM_LOCAL.
Update: Here's the latest code:
$handle = printer_open("Send To OneNote 2010");
printer_start_doc($handle, "My Document");
printer_start_page($handle);
$filename='index.html';
$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);
我已获得此代码以将空白页打印到正确的打印机,但我无法打印传递给printer_write 的字符串.我确认 $contents
正确填充了我的测试 html 文件的内容.无论我提供什么作为第二个 arg(要打印的字符串),我都会得到一个空白页.有什么我遗漏的东西至少可以让我在页面上打印一些文本吗?
I've gotten this code to print a blank page to the correct printer, but I'm unable to print the strings I pass to printer_write. I confirmed that $contents
is properly filled with the contents of my test html file. No matter what I provide as the second arg (string to be printed) I get a blank page. Is there something I'm missing to at least allow me to print some text onto a page?
或者有没有更好的方法来做到这一点(使用 PHP/javascript 文件)?我想要做的是通过 CLI 应用程序打印出现的网页(包括 CSS),该网站是用 PHP 编写的,我试图将复杂性降至最低.如果有更好的方法来打印这些(显然转换为 PDF 和打印是一个选项)我是开放的,但听起来这是 PHP 中最简单/事实上的方法.
Alternately is there a better way to do this (using PHP/javascript files)? What I am trying to do is print web pages as they appear (CSS included) via a CLI app, the web siteis written in PHP and I'm trying to minimize complexity. If there is a better way to print these (converting to PDF and printing is an option apparently) I'm open but it sounded like this was the simplest/de facto method in PHP.
我对printer.dll 搞了很长时间并且厌烦了.
i messed around with printer.dll for ages and got sick of it.
不确定它是否有多大用处,但我购买了此应用程序http://www.coolutils.com/TotalPDFPrinter
not sure if its much use, but i purchased this application http://www.coolutils.com/TotalPDFPrinter
它让我从 php 的 cmd 行打印 pdf 文件,这对我来说效果很好,但它确实有一个弹出屏幕,只有在您购买服务器版本时才能摆脱(如果您需要apache 作为服务运行).显然非弹出版本要贵得多.
and it lets me print pdf files from the cmd line from php, which worked well for me, but it does have a popup screen which you can only get rid of if you purchase the server version (which you will need if your apache is running as a service). obviously the non-popup version is way more expensive.
我挣扎的一件事是获取可用的打印机列表,所以我用 C# 编写了这个小应用程序,它以纯文本形式输出打印机列表,然后使用 php 调用它并将它们放入下拉列表在我的网络表单上.
one thing i struggled with, was getting a list of printers available, so i wrote this little app in C# that spits out a list of printers as plain text, and then use php to call that and put them into a drop list on my web forms.
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Printing;
namespace printerlist
{
class Program
{
static void Main(string[] args)
{
foreach (String printer in PrinterSettings.InstalledPrinters)
{
Console.WriteLine(printer.ToString());
}
}
}
}
这篇关于用 PHP 打印到打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!