I have a Peripage A4 continuous paper roll thermal printer, connected via USB-C to a MacBook with 13.3.1. Printing works fine from within all applications and via the commandline using lpr
:
$ lorem --faust --lines 20 --randomize | lpr -P "PeriPage_A4" -o orientation-requested=1
prints 20 lines of random (randomized Goethe, in this case) lorem ipsum.
Is there a way I can tell lpr
to "not fill an A4 page with nothingness" but rather just print the text, the stop (so that only the lines that contain text are printed), or print "one line at a time" (again, of course, without filling the rest of the page with nothing)? Other than in this example I do not know the amount of text, it varies with each print.
Have: Want:
┌──────────────┐ ┌──────────────┐
│lorem ipsum │ │lorem ipsum │
│sit dolor et │ │sit dolor et │
│eniam unque. │ │eniam unque. │
│ │ └──────────────┘
│ │ ▲
│ │ │
│ │ │
│ │ │
│ │ │
│ │ printing stopped.
│ │
│ │
│ │ lots of blank paper
│ │ │
│ │ ◄─────────┘
│ │
└──────────────┘
I have tried a Python script, but the printer does not seem to understand ESC/POS stuff:
#!/usr/bin/env python3
import sys
import time
from escpos.printer import Usb
# Configure the printer
printer = Usb(0x09c5, 0x0200, in_ep=0x81, out_ep=0x02)
# Reset the printer
printer.hw('reset')
# Read the input text from stdin
input_text = sys.stdin.read()
# Print the input text
printer.text(input_text)
# Add a small delay
time.sleep(1)
# Cut the paper
#printer.cut()
# Close the printer connection
printer.close()