Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python在Linux上直接向打印机打印字节字符串_Python_Linux_Printing_Reportlab - Fatal编程技术网

Python在Linux上直接向打印机打印字节字符串

Python在Linux上直接向打印机打印字节字符串,python,linux,printing,reportlab,Python,Linux,Printing,Reportlab,临时文件可以使用 subprocess.run(["lp", "-d", "<printer>", tmp]) 此代码启动打印作业,但大小为0k且状态为保持。我猜您缺少一个lpr.communicate()调用,请与以下内容进行比较: buffer = BytesIO() c = canvas.Canvas(buffer) c.drawString(100, 100, "Hello World") c.showPage() c.save() pdf = buffer.getva

临时文件可以使用

subprocess.run(["lp", "-d", "<printer>", tmp])

此代码启动打印作业,但大小为
0k
且状态为保持。

我猜您缺少一个
lpr.communicate()
调用,请与以下内容进行比较:

buffer = BytesIO()
c = canvas.Canvas(buffer)
c.drawString(100, 100, "Hello World")
c.showPage()
c.save()

pdf = buffer.getvalue()
lpr = subprocess.Popen("/usr/bin/lpr", stdin=subprocess.PIPE)
lpr.stdin.write(pdf)
buffer.close()