用 PHP 打印到打印机

Printing to printers in PHP(用 PHP 打印到打印机)
本文介绍了用 PHP 打印到打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试设置 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 打印到打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)