print pdf file to network printer using python

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

    #1

    print pdf file to network printer using python

    Well, Ive been searching through google groups and Ive seen a lot about
    printing a pdf file, but I havent seen a definite answer. I tried this
    code:

    f = open(printer_pa th, 'w')
    f.write(pdffile _path)
    f.close()

    Basically it doesnt work and what it prints out is the value of
    pdffile_path variable. If anyone can offer some help, Id appreaciate it
    thanks!

    --Barry

  • Grant Edwards

    #2
    Re: print pdf file to network printer using python

    On 2005-07-21, scrimp <scrimp212@yaho o.com> wrote:[color=blue]
    > Well, Ive been searching through google groups and Ive seen a lot about
    > printing a pdf file, but I havent seen a definite answer. I tried this
    > code:
    >
    > f = open(printer_pa th, 'w')
    > f.write(pdffile _path)
    > f.close()
    >
    > Basically it doesnt work and what it prints out is the value of
    > pdffile_path variable. If anyone can offer some help, Id appreaciate it
    > thanks![/color]

    You forgot to read the data from the pdf file.

    f = open(printer_pa th, 'w')
    f.write(open(pd ffile_path,'rb' ).read())
    f.close()

    --
    Grant Edwards grante Yow! Yow! It's a hole
    at all the way to downtown
    visi.com Burbank!

    Comment

    • scrimp

      #3
      Re: print pdf file to network printer using python

      I just tried it and all that printed out was garbage. I found another
      way to do it. It all depends on what you wanna do. If u want to print
      to the default printer (easiest way) then just use this line:

      win32api.ShellE xecute(0, "print", file_path, None, ".", 0)

      file_path of course being the full path of the file

      Now, if u wanna print to another printer then u have to add a line:

      win32print.SetD efaultPrinter(p rinter_name)
      win32api.ShellE xecute(0, "print", file_path, None, ".", 0)

      printer_name being the NAME of the printer that is installed on the
      machine not the path of the printer

      Everything works good and the PDF file comes out perfect. The only
      problem I have is that ShellExecute command starts up a blank session
      of Acrobat Reader. I need that Acrobat to be terminated. I think by
      using ShellExecute it does not provide the correct handle that python
      needs to terminate the process. Any suggestions?

      Comment

      Working...