Print to printer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • avnit

    Print to printer

    I can't seem to figure out how to print with my printer using python.
    I'm using Mac OSX 10.4. I was thinking maybe something with
    applescript. Does anyone know?

  • SPE - Stani's Python Editor

    #2
    Re: Print to printer

    You should be more specific. What do you want to print? Text, images,
    ....
    If you want a cross platform solution you could use wxPython:


    For text you could use wxHtmlEasyPrint ing:


    For mac solutions, you better post this on the pythonmac mailing list.

    Stani
    --
    Free python IDE for Windows,Mac & Linux with UML,PyChecker,Debugger,GUI design,Blender & more



    Comment

    • avnit

      #3
      Re: Print to printer

      I just want to print text. I'll try macpython. Thanks for the help.

      Comment

      • avnit

        #4
        Re: Print to printer

        I just want to print text. I'll try macpython. Thanks for the help.

        Comment

        • Magnus Lycka

          #5
          Re: Print to printer

          avnit wrote:[color=blue]
          > I can't seem to figure out how to print with my printer using python.
          > I'm using Mac OSX 10.4. I was thinking maybe something with
          > applescript. Does anyone know?[/color]

          Mac OSX is unix, right?

          This ought to work then:[color=blue][color=green][color=darkred]
          >>> import os
          >>> printer = os.popen('lpr', 'w')
          >>> printer.write(' This is a test.\n')
          >>> printer.close()[/color][/color][/color]

          Try to get 'lpr' or 'lp' to work from a command line.
          You should be able to use 'lpstat -p' to figure out
          printer names if you need that (then use 'lpr -P ps'
          to print to a printer called ps.)

          Comment

          • avnit

            #6
            Re: Print to printer

            Wow. That worked perfectly. Thanks a lot.

            Comment

            • avnit

              #7
              Re: Print to printer

              Do you know if there's a way to print a file? I'm trying to print an
              HTML file, so your solution is good, but doesn't really work for me.
              Just reading the HTML file and the printing the content obviously
              wouldn't work. I also tried:
              [color=blue][color=green][color=darkred]
              >>> printer.write(f ile('path/to/file.ext'))[/color][/color][/color]

              but apparently this function only takes strings as parameters.

              Thanks.

              Comment

              • Magnus Lycka

                #8
                Re: Print to printer

                avnit wrote:[color=blue]
                > Do you know if there's a way to print a file? I'm trying to print an
                > HTML file, so your solution is good, but doesn't really work for me.
                > Just reading the HTML file and the printing the content obviously
                > wouldn't work. I also tried:
                >[color=green][color=darkred]
                > >>> printer.write(f ile('path/to/file.ext'))[/color][/color]
                >
                > but apparently this function only takes strings as parameters.[/color]

                Unless you have a strong desire to waste time and memory by opening
                the file reading the content into a string and then call printer.write,
                you could simply do something along the lines of this:

                fn = 'path/to/file.ext'
                printer = 'ps'
                print_cmd = 'lpr -P %s %s'
                os.system(print _cmd % (printer, fn))

                Comment

                Working...