0

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.

bdoubleu
  • 5,568
  • 2
  • 20
  • 53

1 Answers1

0

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

Bruno Ranieri
  • 655
  • 6
  • 9