By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,551 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,551 IT Pros & Developers. It's quick & easy.

how to print pdf with python on a inkjet printer.

P: n/a
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.
Nov 16 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
"krishnakant Mane" <re**********@gmail.comwrote:
>
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, ti**@probo.com
Providenza & Boekelheide, Inc.
Nov 17 '06 #2

P: n/a

krishnakant Mane wrote:
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/2114252and 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

Nov 17 '06 #3

P: n/a
Leo Kislov wrote:
CUPS only have command line interface:
<http://www.cups.org/documentation.php/options.html>
My mistake: CUPS actually has official C API
<http://www.cups.org/documentation.php/api-cups.htmland unofficial
python bindings <http://freshmeat.net/projects/pycups/>.

Nov 17 '06 #4

P: n/a
On 17/11/06, Tim Roberts <ti**@probo.comwrote:
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*.
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.
Nov 17 '06 #5

P: n/a
krishnakant Mane wrote:
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/...o_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>

Nov 17 '06 #6

P: n/a
On 17/11/06, Fredrik Lundh <fr*****@pythonware.comwrote:
http://tgolden.sc.sabren.com/python/...o_i/print.html

or possibly:

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.
Nov 17 '06 #7

P: n/a
krishnakant Mane wrote:
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/showf...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>

Nov 17 '06 #8

P: n/a
krishnakant Mane wrote:
>>
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, ti**@probo.com
Providenza & Boekelheide, Inc.

Nov 17 '06 #9

P: n/a
At Friday 17/11/2006 17:40, Tim Roberts wrote:
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.
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
Nov 18 '06 #10

P: n/a
Gabriel Genellina schrieb:
At Friday 17/11/2006 17:40, Tim Roberts wrote:
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.

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)
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

Nov 19 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.