0

I have searched everywhere for this and could not find an answer. I am using os.system to print to a printer, but it prints it off as a portrait and I need it to print off as Landscape. I assume there is a simple way to add something within the os.system command to get this to work, but I cannot figure out what it is. This is how I am printing it off right now:

os.system('lp "file.png"')
hunter21188
  • 405
  • 2
  • 7
  • 29

2 Answers2

1

Try os.system('lp -o landscape "file.png"')

Jahaja
  • 3,222
  • 1
  • 20
  • 11
  • I tried that, however, all it did was shift the image to the right side of the page. I also tried os.system('lpr -o landscape "file.png"'). – hunter21188 Jul 30 '13 at 19:45
  • Hmm, anything strange in the options if you use lpoptions -l? – Jahaja Jul 30 '13 at 19:56
  • The only thing that sticks out is the "Rotate/180 Rotate:" is marked as false instead of true. I would think if that would be true it would print properly? Outside of that, everything seems normal. – hunter21188 Jul 30 '13 at 20:09
  • Turns out it was a bug in the printer software. I reverted it to a previous version and the -o landscape worked. Thanks! – hunter21188 Jul 30 '13 at 21:09
0

Ok it was a bug, but just a hint on convenience:

I usually replace os.system with the following snippet

from subprocess import (PIPE, Popen)


def invoke(command):
    '''
    Invoke process and return its output.
    '''
    return Popen(command, stdout=PIPE, shell=True).stdout.read()

or if you want to be more comfortable with sh, try

from sh import lp

lp('-o', 'landscape', 'file.png')
Yauhen Yakimovich
  • 13,635
  • 8
  • 60
  • 67