Python printing bytes string directly to printer on Linux

bdoubleu

A temp file can print by using

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

But is it possible to print a bytes string representing a ReportLab generated pdf?

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()

This code starts a print job but with a size of 0k and a status of Held.

Bruno Ranieri

I guess you are missing a lpr.communicate() call, compare with: Understanding Popen.communicate

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

print a string directly to printer

From Dev

linux print directly to network printer that IS NOT installed

From Dev

Printer is not printing

From Dev

SML : Replacing a concat by printing the string directly

From Dev

Trouble printing to a Brother HL3170CDW printer on Linux

From Dev

The java printing code is working,send to printer but not print anything(java in python)

From Dev

The java printing code is working,send to printer but not print anything(java in python)

From Dev

Python Printing the String Result

From Dev

Printing to a Printer DC with MFC

From Dev

Printer printing light pages

From Dev

Printer and software for label printing?

From Dev

Printer printing light pages

From Dev

Epson Printer Not Printing

From Dev

Brother printer not printing

From Dev

JavaFX and printing to Epson printer

From Dev

Python converting bytes to string

From Dev

Python String to Hex Bytes

From Dev

Printing string as integers in python 3

From Dev

output error in printing string in python

From Dev

How to set up LPD/LPR printing system for sharing a postscript printer on Linux?

From Dev

How to print to directly to a wireless printer

From Dev

How to print to directly to a wireless printer

From Dev

LPR print, can it be directly to printer?

From Dev

Printing a specified BMP file to printer

From Dev

Printing a file and configure printer settings

From Dev

Crystal report printing to wrong printer

From Dev

Printing data to printer using PHP

From Dev

Issues with printing a custom view to printer

From Dev

Printing Image with Bluetooth Printer in Flutter