【问题标题】:Automatic printing from website, to labelprinter and laserprinter从网站自动打印到标签打印机和激光打印机
【发布时间】:2017-06-02 22:55:24
【问题描述】:

我正在尝试找到一种方法来打印从我们基于 php 的网站下载的 pdf。

目前我们必须自己指定每台打印机(small labelprinter-large labelprinter-laserjet),但我们想要这样的工作流程:

  • 在网站上单击小标签图标。
  • 会生成带有标签的 pdf,并获取文件名,其中 .pdf 存储在文件服务器上的 users 文件夹中。
  • 基于文件的前缀和后缀,监视文件夹的监视程序向文件中指定的打印机发送命令以打印。

基本上,我的目标是使用自助服务终端打印模式,每个用户都可以指定附近应该使用哪台打印机。

这是一个很容易实现的功能吗?

【问题讨论】:

  • 容易吗?我会说不是。可以实现吗?我肯定会说。这取决于您要询问的过程的确切部分。使用 PHP 生成和保存 PDF 非常简单直接(mpdf1.com/mpdf/index.phptcpdf.orgfpdf.org/?lang=en 等)。监控和打印文件的程序会稍微复杂一些——但应该仍然可以实现。这有点超出我的专业知识,但我建议研究 Python:python.org
  • 你用的是windows还是linux?

标签: php pdf printing


【解决方案1】:

用 PHP 做这个比较难,用 Python 会更容易

对于窗户

您必须制作一个 Python 脚本,该脚本每 10 秒(或更短时间)扫描一个文件夹,您可以在其中放置所有要打印的文件。

while True:
    files_in_dir = os.listdir(os.path.join('path to the scanned folder'))
    time.sleep(10) # sleep 10 seconds before the new scan

然后,您可以使用gsprint 将文件发送到打印机

p = subprocess.Popen(
    ['path_to_gsprint.exe', '-printer', 'printer_name', 'fullpath_file'],
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE)
out, err = p.communicate()
if out:
    print Tools.format_txt(out)
if err:
    print Tools.format_txt(err, level="error")

文件打印后,将其删除或移至其他文件夹,以免再次扫描。

os.rename(filename, 'path to printed folder' + filename) # move file
os.remove(filename) # delete file

Linux 版

在 linux 上,脚本非常相似,使用 Python,扫描一个文件夹,然后使用lp 命令将找到的文件发送到打印机

lp -d PRINTER_NAME *.pdf

同样,一旦文件被打印,删除或移动它们。


使用此技术,您将无法获得即时打印,您将不得不等待脚本扫描文件夹,但如果您在两次扫描之间设置较短的时间,这将不是问题

【讨论】:

    猜你喜欢
    • 2016-03-25
    • 1970-01-01
    • 1970-01-01
    • 2019-08-26
    • 2012-05-28
    • 2011-04-13
    • 1970-01-01
    • 2014-03-01
    • 2012-09-25
    相关资源
    最近更新 更多