print pdf file to network printer using python

S

scrimp

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_path, '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
 
G

Grant Edwards

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_path, '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!

You forgot to read the data from the pdf file.

f = open(printer_path, 'w')
f.write(open(pdffile_path,'rb').read())
f.close()
 
S

scrimp

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.ShellExecute(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.SetDefaultPrinter(printer_name)
win32api.ShellExecute(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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top