使用python打印后点阵打印机不会移动到下一个撕纸位置
我正在使用 Epson FX2175 点阵打印机和 win32print python 库向打印机发出命令。打印完成后,纸张不会移动到下一个撕纸位置。
我尝试在最后发送 FF(换页)命令,但它使纸张前进太多,而不是按照我的纸张尺寸(即 15.4 厘米)移动。纸张尺寸已在打印机首选项 > 中配置纸张尺寸>用户定义。
下面是我的Python代码
import os, sys
import win32print
def formatData(args):
cnt = 1;
decimal_form_feed = 12
decimal_line_feed = 10
decimal_carriage_return = 13
byteArr = bytearray()
# Reverse feed
# byteArr.extend(bytes("\u001bj2", "utf-8"))
# byteArr.extend(bytes("\u001b$0", "utf-8"))
# ESC J Advance print position vertically
# param n where 0 <= n <=255
# Advances vertical position n/216 or n/180 inches
# Set page size in terms of line numbers
# byteArr.extend(bytes("\u001bC10", "utf-8"))
print(len(args))
while(cnt < len(args)):
if args[cnt]=="R":
temp = bytes (args[cnt+1], "utf-8")
byteArr.extend(temp)
#print(byteArr)
elif args[cnt]=="RB":
temp = bytes ("\u001bE"+args[cnt+1]+"\u001bF", "utf-8")
byteArr.extend(temp);
#print(byteArr)
elif args[cnt]=="D":
temp = bytes ("\u001b\u000e"+args[cnt+1]+"\u001b\u0012", "utf-8")
byteArr.extend(temp);
elif args[cnt]=="DB":
temp = bytes ("\u001b\u000e"+args[cnt+1]+"\u001b\u0012", "utf-8")
byteArr.extend(temp);
elif args[cnt]=="newline":
temp = bytes ("\n", "utf-8")
byteArr.extend(temp);
cnt = cnt+1
continue
elif args[cnt]=="lf":
mCnt = 0
while mCnt < int(args[cnt+1]):
mCnt = mCnt+1
byteArr.extend(bytes("\n", "utf-8"))
#byteArr.extend(bytes("\u001bJ1", "utf-8"))
elif args[cnt]=="rf":
mCnt = 0
while mCnt < int(args[cnt+1]):
byteArr.extend(bytes("\u001bj2", "utf-8"))
mCnt = mCnt+1
cnt = cnt+2;
byteArr.extend(decimal_carriage_return.to_bytes(2, 'big'))
byteArr.extend(decimal_form_feed .to_bytes(2, 'big'))
#byteArr.extend(decimal_carriage_return.to_bytes(2, 'big'))
#byteArr.extend(decimal_line_feed.to_bytes(2, 'big'))
print(byteArr)
mBytes = bytes(byteArr)
return mBytes
printer_name = win32print.GetDefaultPrinter ()
raw_data = formatData(sys.argv);
hPrinter = win32print.OpenPrinter (printer_name)
try:
hJob = win32print.StartDocPrinter (hPrinter, 1, (raw_data.decode("utf-8"), None, "RAW"))
try:
win32print.StartPagePrinter (hPrinter)
win32print.WritePrinter (hPrinter, raw_data)
win32print.EndPagePrinter (hPrinter)
finally:
win32print.EndDocPrinter (hPrinter)
finally:
win32print.ClosePrinter (hPrinter)
,我使用本手册作为参考 Epson EscP 手册参考
非常感谢您的帮助,因为我为此苦苦挣扎了近 5 天。
I am using Epson FX2175 dot matrix printer and win32print python library to give commands to printer. After printing is completed paper doesn't moves to next tear off position.
I tried sending FF(form feed) command at the end but it advances paper too much instead of moving as my paper size i.e. 15.4 cm. Paper size has been configured in printer preferences > paper size > user defined.
Below is my python code
import os, sys
import win32print
def formatData(args):
cnt = 1;
decimal_form_feed = 12
decimal_line_feed = 10
decimal_carriage_return = 13
byteArr = bytearray()
# Reverse feed
# byteArr.extend(bytes("\u001bj2", "utf-8"))
# byteArr.extend(bytes("\u001b$0", "utf-8"))
# ESC J Advance print position vertically
# param n where 0 <= n <=255
# Advances vertical position n/216 or n/180 inches
# Set page size in terms of line numbers
# byteArr.extend(bytes("\u001bC10", "utf-8"))
print(len(args))
while(cnt < len(args)):
if args[cnt]=="R":
temp = bytes (args[cnt+1], "utf-8")
byteArr.extend(temp)
#print(byteArr)
elif args[cnt]=="RB":
temp = bytes ("\u001bE"+args[cnt+1]+"\u001bF", "utf-8")
byteArr.extend(temp);
#print(byteArr)
elif args[cnt]=="D":
temp = bytes ("\u001b\u000e"+args[cnt+1]+"\u001b\u0012", "utf-8")
byteArr.extend(temp);
elif args[cnt]=="DB":
temp = bytes ("\u001b\u000e"+args[cnt+1]+"\u001b\u0012", "utf-8")
byteArr.extend(temp);
elif args[cnt]=="newline":
temp = bytes ("\n", "utf-8")
byteArr.extend(temp);
cnt = cnt+1
continue
elif args[cnt]=="lf":
mCnt = 0
while mCnt < int(args[cnt+1]):
mCnt = mCnt+1
byteArr.extend(bytes("\n", "utf-8"))
#byteArr.extend(bytes("\u001bJ1", "utf-8"))
elif args[cnt]=="rf":
mCnt = 0
while mCnt < int(args[cnt+1]):
byteArr.extend(bytes("\u001bj2", "utf-8"))
mCnt = mCnt+1
cnt = cnt+2;
byteArr.extend(decimal_carriage_return.to_bytes(2, 'big'))
byteArr.extend(decimal_form_feed .to_bytes(2, 'big'))
#byteArr.extend(decimal_carriage_return.to_bytes(2, 'big'))
#byteArr.extend(decimal_line_feed.to_bytes(2, 'big'))
print(byteArr)
mBytes = bytes(byteArr)
return mBytes
printer_name = win32print.GetDefaultPrinter ()
raw_data = formatData(sys.argv);
hPrinter = win32print.OpenPrinter (printer_name)
try:
hJob = win32print.StartDocPrinter (hPrinter, 1, (raw_data.decode("utf-8"), None, "RAW"))
try:
win32print.StartPagePrinter (hPrinter)
win32print.WritePrinter (hPrinter, raw_data)
win32print.EndPagePrinter (hPrinter)
finally:
win32print.EndDocPrinter (hPrinter)
finally:
win32print.ClosePrinter (hPrinter)
I am using this manual for reference Epson EscP manual reference
Any help is very much appreciated since I am struglling with this for almost 5 days.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于面临同样挑战的人,
我无法找到如何以编程方式完成此操作的答案,但通过更改打印机中的默认设置,我能够完成工作。打印机进行了以下更改:
可以使用以下命令设置页面大小,但有些不起作用。只是把它放在它可能对其他人有用的地方:
注意:我通过打印机软件进行了所有更改,但这也不起作用。
For people who face same challenge
I was unable to find answer how to do it programatically but by making changes to default settings in printer I was able to get my work done. Followng changes were made in printer:
Page size can be set using following command but it was some how not working. Just putting it so that it may work for someone else:
Note: I made all changes through printer software but that too was not working.