Discussion:
how to print pdf with python on a inkjet printer.
Leo Kislov
2006-11-17 08:54:02 UTC
Permalink
hello all.
I am developing an ncurses based python application that will require
to create pdf reports for printing.
I am not using py--qt or wx python.
it is a consol based ui application and I need to make a pdf report
and also send it to a lazer or ink jet printer.
is it possible to do so with python?
or is it that I will have to use the wxpython library asuming that
there is a print dialog which can open up the list of printers?
if wx python and gui is the only way then it is ok but I will like to
keep this application on the ncurses side.
Assuming you are on a UNIX-like system, you really need to setup CUPS
<http://www.cups.org/> (or may be your system already provides CUPS).
PDF seems to be the future intermediate format for UNIX printing
<http://www.linux.com/article.pl?sid=06/04/18/2114252> and CUPS already
supports printing PDF files, just run "lp your_file.pdf" to print a
file. CUPS only have command line interface:
<http://www.cups.org/documentation.php/options.html>

-- Leo
Tim Roberts
2006-11-17 07:16:11 UTC
Permalink
hello all.
I am developing an ncurses based python application that will require
to create pdf reports for printing.
I am not using py--qt or wx python.
it is a consol based ui application and I need to make a pdf report
and also send it to a lazer or ink jet printer.
is it possible to do so with python?
Making the PDF is easy. Go get ReportLab from www.reportlab.org. I
consider it the best Python PDF solution.

Printing is more complicated, because you actually need something that can
RENDER the PDF. The most common such renderer is the Acrobat Reader, and
you can actually call the Acrobat Reader from a command line with a
parameter that tells it to print the file automatically. The only
disadvantage is that using that method will only print to the "default"
printer.
or is it that I will have to use the wxpython library asuming that
there is a print dialog which can open up the list of printers?
Even if you got the list of printers, what would you do with it?
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
Thomas Heller
2006-11-19 16:11:50 UTC
Permalink
double wow! as it is my customer wants me to print to the default
printer.
can you please help me with the command for rendering the pdf to the
printer with acrobat using python?
You'll have to use the registry to find "acrord32", but once you find
os.system( "\\Program Files\\Adobe\\Acrobat 7.0\\Reader\acrord32.exe
/p xxx.pdf" )
The /p switch requests printing.
Or just let Windows do the dirty work of locating Adobe Reader,
import win32api
win32api.ShellExecute(0, "print", path/to/document.pdf, None, None, 0)
Note that in Pyhton2.5, os.startfile was extended to accept an optional
second parameter; so
os.startfile(path/to/document.pdf, "print")
should also work.

Thomas
km
2006-11-19 16:28:11 UTC
Permalink
i dont see os.startfile in python2.5 installation on my system :-(
KM
double wow! as it is my customer wants me to print to the default
printer.
can you please help me with the command for rendering the pdf to the
printer with acrobat using python?
You'll have to use the registry to find "acrord32", but once you find
os.system( "\\Program Files\\Adobe\\Acrobat
7.0\\Reader\acrord32.exe
/p xxx.pdf" )
The /p switch requests printing.
Or just let Windows do the dirty work of locating Adobe Reader,
import win32api
win32api.ShellExecute(0, "print", path/to/document.pdf, None, None, 0)
Note that in Pyhton2.5, os.startfile was extended to accept an optional
second parameter; so
os.startfile(path/to/document.pdf, "print")
should also work.
Thomas
--
http://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061119/3dc4247e/attachment.html>
Fredrik Lundh
2006-11-17 11:48:56 UTC
Permalink
double wow! as it is my customer wants me to print to the default printer.
can you please help me with the command for rendering the pdf to the
printer with acrobat using python?
see:

http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html

or possibly:

http://www.planetpdf.com/forumarchive/49365.asp

now go donate some of what the customer is paying you to solve this
problem for him to the PSF ;-)

</F>
Fredrik Lundh
2006-11-17 19:38:47 UTC
Permalink
I can't figure out where is the win32api module in my system.
I think I need to download it.
I tried to search but did not find it.
googling for "python win32api" gives you:

http://sourceforge.net/project/showfiles.php?group_id=78018

among the first few hits. as for documentation, it's just a binding for
the win32 api:s, which are extensively documented over at microsoft.com.

</F>
krishnakant Mane
2006-11-17 19:20:29 UTC
Permalink
Post by Fredrik Lundh
http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html
http://www.planetpdf.com/forumarchive/49365.asp
I can't figure out where is the win32api module in my system.
I think I need to download it.
I tried to search but did not find it.
what is the url for this module and does it also have documentation.
thanking you.
Krishnakant.

Gabriel Genellina
2006-11-18 01:32:14 UTC
Permalink
double wow! as it is my customer wants me to print to the default
printer.
can you please help me with the command for rendering the pdf to the
printer with acrobat using python?
You'll have to use the registry to find "acrord32", but once you find
os.system( "\\Program Files\\Adobe\\Acrobat 7.0\\Reader\acrord32.exe
/p xxx.pdf" )
The /p switch requests printing.
Or just let Windows do the dirty work of locating Adobe Reader,
figuring out the parameters and such:

import win32api
win32api.ShellExecute(0, "print", path/to/document.pdf, None, None, 0)
--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ?gratis!
?Abr? tu cuenta ya! - http://correo.yahoo.com.ar
krishnakant Mane
2006-11-17 11:14:33 UTC
Permalink
Post by Tim Roberts
Making the PDF is easy. Go get ReportLab from www.reportlab.org. I
consider it the best Python PDF solution.
wow! you solved my major problem before I even asked it. seams that
python programmers also have dynamic mind reading capability *smile*.
Post by Tim Roberts
Printing is more complicated, because you actually need something that can
RENDER the PDF. The most common such renderer is the Acrobat Reader, and
you can actually call the Acrobat Reader from a command line with a
parameter that tells it to print the file automatically. The only
disadvantage is that using that method will only print to the "default"
printer.
double wow! as it is my customer wants me to print to the default printer.
can you please help me with the command for rendering the pdf to the
printer with acrobat using python?
that essentially solves my most important problem.
else I was thinking to create an excel spreadsheet as a last alternative.
out of my curocity, I want to know if there are libraries that can
create excel spreadsheets?

I also wanted to know if there is a common dialog for listing out
printers under windows?
so in future if I make this software in GUI, I can at list help the
user select the printer from the list.
thanks,
Krishnakant.
Tim Roberts
2006-11-17 20:40:57 UTC
Permalink
double wow! as it is my customer wants me to print to the default printer.
can you please help me with the command for rendering the pdf to the
printer with acrobat using python?
You'll have to use the registry to find "acrord32", but once you find
it, you just do:
os.system( "\\Program Files\\Adobe\\Acrobat 7.0\\Reader\acrord32.exe
/p xxx.pdf" )
The /p switch requests printing.
that essentially solves my most important problem.
else I was thinking to create an excel spreadsheet as a last alternative.
out of my curocity, I want to know if there are libraries that can
create excel spreadsheets?
There are several ways. One way is to just bring up Excel itself and
send it commands via COM. Several times, I've written my data as a
comma-separated file (which Excel understands), then brought up Excel as
a COM component, loaded the file, then used Excel commands to format the
columns.

There are also a couple of Python modules which purport to be able to
read and write .xls files directly. There's xlrd, but there's a newer
one whose name escapes me. I thought it was a pun, like "xlerator," but
that's not right.
I also wanted to know if there is a common dialog for listing out
printers under windows?
so in future if I make this software in GUI, I can at list help the
user select the printer from the list.
Yes, there is a standard "print" dialog for Windows that shows you the
familiar dialog, with the list of printers and all of the options. In
wxPython, I believe it is called wx.PrintDialog.

In Pywin32, win32print.EnumPrinters can give you the list of available
printers.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
Leo Kislov
2006-11-17 09:27:01 UTC
Permalink
Post by Leo Kislov
<http://www.cups.org/documentation.php/options.html>
My mistake: CUPS actually has official C API
<http://www.cups.org/documentation.php/api-cups.html> and unofficial
python bindings <http://freshmeat.net/projects/pycups/>.
krishnakant Mane
2006-11-16 18:11:36 UTC
Permalink
hello all.
I am developing an ncurses based python application that will require
to create pdf reports for printing.
I am not using py--qt or wx python.
it is a consol based ui application and I need to make a pdf report
and also send it to a lazer or ink jet printer.
is it possible to do so with python?
or is it that I will have to use the wxpython library asuming that
there is a print dialog which can open up the list of printers?
if wx python and gui is the only way then it is ok but I will like to
keep this application on the ncurses side.

thanks.
Krishnakant.
Continue reading on narkive:
Search results for 'how to print pdf with python on a inkjet printer.' (Questions and Answers)
3
replies
how to make a monty python costume?
started 2009-10-04 10:32:33 UTC
halloween
Loading...