【问题标题】:printing from php to real printer从php打印到真正的打印机
【发布时间】:2020-11-30 20:05:31
【问题描述】:

一段时间以来,我一直在批处理文件中使用以下脚本将 PDF 文件打印到打印机:

c:\path\to\PDFtoPrinter.exe c:\path\to\file.pdf "\\ip\printer"

我曾希望使用 exec() 将其简单地添加到 PHP 脚本中,一切都会奏效,但不行。

exec('c:\\path\\to\\PDFtoPrinter.exe c:\\path\\to\\file.pdf "\\\ip\\printer"');

我的另一个想法是将命令写入 bat 文件并从我的 PHP 脚本中执行该文件,但也没有成功。

有什么建议吗?

exec("\\path\\to\\PDFtoPrinter.exe \\path\\to\\file.pdf '\\ip\printer'");

【问题讨论】:

  • exec() 一样的单引号文字不会逃避那些反斜杠。删除双反斜杠,或改用双引号文字。
  • 另外,这样写的你会在 ip 之前缺少一个反斜杠
  • 喜欢我的最后一行吗?
  • 正确的做法是 exec("\\path\\to") 转义反斜杠。只有双引号文字才会尊重转义字符。但单引号不正确,因为每个字符都是字面意思。
  • 所以我的最后一行应该是正确的?

标签: php printing


【解决方案1】:

以下对我有用:

exec("c:\\path\\to\\PDFtoPrinter.exe c:\\path\\to\\pdf.file \"printer-name\"");

【讨论】:

    猜你喜欢
    • 2014-11-16
    • 2012-05-28
    • 2017-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多