how to print pdf with python on a inkjet printer.

K

krishnakant Mane

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.
 
T

Tim Roberts

krishnakant Mane said:
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?
 
L

Leo Kislov

krishnakant said:
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
 
K

krishnakant Mane

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.
 
D

Dennis Lee Bieber

wow! you solved my major problem before I even asked it. seams that
python programmers also have dynamic mind reading capability *smile*.

Wait for the next time someone invokes Guido's time-machine said:
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?

For the most part, I think it involves just a /p on the command
line. Though I had an annoyance the last time I tried it -- while Reader
stayed minimized during the print, it did not terminate after the print;
it remained in the task-bar.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
T

Tim Roberts

krishnakant said:
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.
 
G

Gabriel Genellina

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
 
T

Thomas Heller

Gabriel said:
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
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top