gpt4 book ai didi

printer-control-language - 我可以将 PCL5 转义序列打印到基于非 PCL 主机的打印机吗?

转载 作者:行者123 更新时间:2023-12-04 08:44:25 27 4
gpt4 key购买 nike

我有 HP LJ P1005 打印机,它是非 PCL(基于主机)打印机。它有一个专用的驱动程序link to the driver .支持 PCL5 的 HP 通用打印驱动程序 (HP-UPD) 不支持它。 A list of supported UPD printers

我的问题是如何在这台打印机上使用 PCL5 转义序列,或者甚至可能吗?这是否意味着如果它是基于主机的,则通过打印机驱动程序的主机 PC 必须解释 PCL5 命令或根本不能使用 PCL5?如何知道驱动程序是否兼容 PCL?如果主机 PC 必须解释 PCL5,打印处理器设置应该是什么样的:RAW、IMF、EMF、winprint TEXT?

最佳答案

好吧,现在我知道我可以创建一个带有 PCL 转义序列的文本文件并解释它并在基于非 PCL 主机的打印机上打印它。

首先,我找到了here如何从 txt 文件创建 pcl 文件的方法。在 Windows 中从 Python 创建 PCL 打印机后,我使用了外部程序 GhostPCL,它是编译的 Ghostscript 解释器,用于从该 pcl 文件创建 PDF 文件 here像这样:

gpcl6win32.exe -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=print.pdf print.pcl

dNOPAUSEdBATCH 用于静默和无交互转换。最后,我安装了gsviewer并从 Python 静默将该 pdf 打印到我默认的基于非 PCL 主机的打印机。我所有的 PCL 代码都被解释并打印到我的廉价打印机上。它在打印时不会打开任何窗口,因此对于客户来说似乎一切正常。

我不是程序员,所以代码不是你见过的最好的,但它可以工作:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Autor: hrvooje
Last edit: June 2017

'pip install pypiwin32 --> for installing win32api'
In python 2: 'python -m pip install pypiwin32'
io module for io.open in Python2, the same as 'open' in Python3
First command line argument is for file name which we want to print:
'python print_rawpcl.py my_pcl_text_file.txt'
"""

import os, sys, io, win32print, win32api, subprocess


def remove_silently(file1):
"""Removing silently files from last time if there are any left"""
try:
os.remove(file1)
except OSError:
pass

# Asign your printers and variables
first_default_printer = win32print.GetDefaultPrinter()
tmp_printer = "local_pcl"
my_pcl_file = "print.pcl"
my_output_pdf = "print.pdf"

# Remove files if they already exist
remove_silently(my_output_pdf)
remove_silently(my_pcl_file)

# If there is command line argument, the first one is our file_to_print
if len(sys.argv) > 1:
file_to_print = sys.argv[1]
else:
file_to_print = "RACUN.TXT"

# Searching for supported PCL printers as default printer
pcl_supported = False
supported_printers = ["2035", "1320", "KONICA", "DIREKT"]
for item in supported_printers:
if item.lower() in first_default_printer.lower():
pcl_supported = True
break
else:
is_supported = False

if pcl_supported == False:
win32print.SetDefaultPrinter(tmp_printer)

# Printing RAW data to the virtual 'local_pcl' printer or to the 'HP LJ P2035'
try:
# rb --> 'read, bytes', string is 'bytes' type, not unicode (Python3)
with io.open(file_to_print, 'rb') as f:
raw_data = f.read()
hPrinter = win32print.OpenPrinter(win32print.GetDefaultPrinter())
try:
hJob = win32print.StartDocPrinter(hPrinter, 1, (
"print_rawpcl.py data", None, "RAW"))
try:
win32print.StartPagePrinter(hPrinter)
win32print.WritePrinter(hPrinter, raw_data)
win32print.EndPagePrinter(hPrinter)
finally:
win32print.EndDocPrinter(hPrinter)
finally:
win32print.ClosePrinter(hPrinter)
except OSError as e:
print("Failed: {}".format(e))

# Convert a pcl file to pdf with GhostPCL (Ghostscript)
# if the default printer is local_pcl
converter_app = 'C:/Python34/ghostpcl-9.21-win32/gpcl6win32.exe'
if win32print.GetDefaultPrinter() == "local_pcl":
subprocess.call(
[converter_app, '-dNOPAUSE', '-dBATCH', '-sDEVICE=pdfwrite',
'-sOutputFile=print.pdf', 'print.pcl'])

# return default printer to the printer that was default at the start
win32print.SetDefaultPrinter(first_default_printer)

# Finally, print that print.pdf to your first default printer silently
gsprint_app = "C:\\Program Files\\Ghostgum\\gsview\\gsprint.exe"
p = subprocess.Popen(
[gsprint_app, my_output_pdf], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
# Waits for the gs process to end
stdout, stderr = p.communicate()
# Remove print.pcl and print.pdf file
remove_silently(my_output_pdf)
remove_silently(my_pcl_file)

# Removes that first txt file
remove_silently(file_to_print)

关于printer-control-language - 我可以将 PCL5 转义序列打印到基于非 PCL 主机的打印机吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44623389/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com