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

PDF Printing support from Python

P: n/a
Hi all... Is there a way to print a PDF file directly from Python
without having Acrobat installed? I know about ReportLab. It's a python
module that lets you create almost any PDF document, but I still don't
know if it supports printing, so I'm looking for a Python module that
could do it. I want to print a PDF file just like if I were doing it
from Acrobat.

Daniel.

Jul 19 '05 #1
Share this Question
Share on Google+
19 Replies


P: n/a
On 2005-04-22, dcrespo <dc*****@gmail.com> wrote:
Hi all... Is there a way to print a PDF file directly from
Python without having Acrobat installed?
Assuming your printing system was setup competently:

os.system("lpr %s" % filename)
I know about ReportLab. It's a python module that lets you
create almost any PDF document, but I still don't know if it
supports printing, so I'm looking for a Python module that
could do it. I want to print a PDF file just like if I were
doing it from Acrobat.


Not sure what you mean by "just like if I were doing it from
Acrobat".

--
Grant Edwards grante Yow! I have seen these
at EGG EXTENDERS in my
visi.com Supermarket... I have read
theINSTRUCTIONS...
Jul 19 '05 #2

P: n/a
Hi Grant Edwards...

Your solution requires a previous installation of Acrobat. Internally,
the OS is sending the pdf file to the Acrobat PDF Driver and then it is
sent to the printer. So you have to have Acrobat installed. Don't you?
I want to avoid it installing a module that could do it (maybe I'm
dreaming:( ). If there's no solution, then I will be very sad :-S

This is what exactly I need to do:
Generate an invoice of 216cm width and 93cm height (1/3 of the height
of a letter paper size), and print it respecting these dimensions. So,
when I print this page on a dot matrix printer, it stops at those 93cm
of height for continuous printing.

What I tried:
I created a pdf file manually with these dimensions, and right-click on
the pdf file, and selected "print". It just work under Windows XP with
Acrobat Reader 7.0, but I want to do it from a Win98 as well.
Unfortunately, there's no Acrobat version under Win98 (the maximun is
5.1) that supports this kind of printing (what I had seen until now).
It prints, but the all paper at letter size :(

Any help? Any other tools? Any one like Cristal Report but for Python?
I heard that wxPython supports some kind of reporting, but I don't know
it. Anyone knows?

Daniel

Jul 19 '05 #3

P: n/a
"dcrespo" <dc*****@gmail.com> writes:
Hi Grant Edwards...

Your solution requires a previous installation of Acrobat. Internally,
the OS is sending the pdf file to the Acrobat PDF Driver and then it is
sent to the printer. So you have to have Acrobat installed. Don't you?
I want to avoid it installing a module that could do it (maybe I'm
dreaming:( ). If there's no solution, then I will be very sad :-S

This is what exactly I need to do:
Generate an invoice of 216cm width and 93cm height (1/3 of the height
of a letter paper size), and print it respecting these dimensions. So,
when I print this page on a dot matrix printer, it stops at those 93cm
of height for continuous printing.

What I tried:
I created a pdf file manually with these dimensions, and right-click on
the pdf file, and selected "print". It just work under Windows XP with
Acrobat Reader 7.0, but I want to do it from a Win98 as well.
Unfortunately, there's no Acrobat version under Win98 (the maximun is
5.1) that supports this kind of printing (what I had seen until now).
It prints, but the all paper at letter size :(

Any help? Any other tools? Any one like Cristal Report but for Python?
I heard that wxPython supports some kind of reporting, but I don't know
it. Anyone knows?

Daniel

When you say "OS", are you talking MS Windows by any chance? On *NIX
(e.g., CUPS+ghostview+foomatic), PDF printing is not via Adobe code.

You could also consider pdf2ps, pdftops, and XPDF.
--
ha************@boeing.com
6-6M21 BCA CompArch Design Engineering
Phone: (425) 294-4718
Jul 19 '05 #4

P: n/a
On 2005-04-22, dcrespo <dc*****@gmail.com> wrote:
Your solution requires a previous installation of Acrobat.
Probably not. Most printing systems I'm familiar with use
ghostscript to render PDF into either postscript (the case on
my machines at home) or whatever raster format the printer
desires (the case at my office).
Internally, the OS is sending the pdf file to the Acrobat PDF
Driver and then it is sent to the printer.
Nope. It's usnig the foomatic print filters which in turn use
ghostscript to render PDF.
So you have to have Acrobat installed. Don't you?
No you just need a good printing system. CUPS + foomatic works
great for me. It knows what to do with postcript, text, PDF,
dvi, and a whole boatload of other fileformats that I don't
ever use.
I want to avoid it installing a module that could do it (maybe
I'm dreaming:( ). If there's no solution, then I will be very
sad :-S

This is what exactly I need to do: Generate an invoice of
216cm width and 93cm height (1/3 of the height of a letter
paper size), and print it respecting these dimensions. So,
when I print this page on a dot matrix printer, it stops at
those 93cm of height for continuous printing.

What I tried: I created a pdf file manually with these
dimensions, and right-click on the pdf file, and selected
"print". It just work under Windows XP with Acrobat Reader
7.0, but I want to do it from a Win98 as well.


Ah. You're using Windows. I didn't know that. I've no clue
what to do under Windows.

--
Grant Edwards grante Yow! .. someone in DAYTON,
at Ohio is selling USED
visi.com CARPETS to a SERBO-CROATIAN
Jul 19 '05 #5

P: n/a
Grant's example is not for Windows, Daniel, but it does illustrate a
certain principle: if you have a printer driver that understands PDF,
or some other external software such as Acrobat Reader that understands
PDF, then printing the PDF is as simple as telling the OS to just print
the file.

If you are looking for some software that acts as a PDF-understanding
interpreter, that must run under Windows 98, I don't know of any
written in Python. However, you might want to research some of the
available non-Python utilities. Ghostscript, for example, is available
at http://www.cs.wisc.edu/~ghost/ and has a version for Win32. You
could easily use Python to drive GhostScript.

Does that fit your needs?

---Peter

Jul 19 '05 #6

P: n/a
"dcrespo" <dc*****@gmail.com> writes:
Hi Grant Edwards...

Your solution requires a previous installation of Acrobat. Internally,
the OS is sending the pdf file to the Acrobat PDF Driver and then it is
sent to the printer. So you have to have Acrobat installed. Don't you?
I want to avoid it installing a module that could do it (maybe I'm
dreaming:( ). If there's no solution, then I will be very sad :-S [...] Acrobat Reader 7.0, but I want to do it from a Win98 as well.
Unfortunately, there's no Acrobat version under Win98 (the maximun is
5.1) that supports this kind of printing (what I had seen until now).
It prints, but the all paper at letter size :(
That doesn't sound like a fundamental problem with AR 5.1 to me --
sounds like you just need to ask it more nicely ;-)

Have you tried the latest version of APFL ghostscript, though (8.51)?

Any help? Any other tools? Any one like Cristal Report but for Python?
I heard that wxPython supports some kind of reporting, but I don't know
it. Anyone knows?


First, decide what qualities you need from your output format, then
decide which format you want, and how to generate and print it. Is it
important that you have one, other, or both of bitmap or vector
output, for example?
John
Jul 19 '05 #7

P: n/a
Thanks a lot... I'm attemping to give it a try :)

Jul 19 '05 #8

P: n/a
> That doesn't sound like a fundamental problem with AR 5.1 to me --
sounds like you just need to ask it more nicely ;-)

AR 7.0 has the function to print exactly the page size you set. AR 5.1
doesn't. Instead, it print it on an existing page size like letter, but
without changing the relative layout of the each line of text respect
each other.

Daniel

Jul 19 '05 #9

P: n/a
>> Your solution requires a previous installation of Acrobat.
Probably not. Most printing systems I'm familiar with use
ghostscript to render PDF into either postscript (the case on
my machines at home) or whatever raster format the printer
desires (the case at my office).
Acrobat (windows) and Ghostscript are PDF drivers.
Internally, the OS is sending the pdf file to the Acrobat PDF
Driver and then it is sent to the printer.

Nope. It's usnig the foomatic print filters which in turn use
ghostscript to render PDF.
What I mean is that the pdf file is sent to a pdf driver (some program
to interpret it)... In your case is ghostscript, and in my case is
Acrobat.
No you just need a good printing system. CUPS + foomatic works
great for me. It knows what to do with postcript, text, PDF,
dvi, and a whole boatload of other fileformats that I don't
ever use.


CUPS + foomatic are the whole megadriver... So it's just a manner of
saying PDF Driver for my study case.

Really thanks for all the information :) I didn't know about
Ghostscript.

Daniel

Jul 19 '05 #10

P: n/a
On 2005-04-22, dcrespo <dc*****@gmail.com> wrote:
Your solution requires a previous installation of Acrobat.
Probably not. Most printing systems I'm familiar with use
ghostscript to render PDF into either postscript (the case on
my machines at home) or whatever raster format the printer
desires (the case at my office).
Acrobat (windows) and Ghostscript are PDF drivers.


No, ghostscript isn't a "driver". it's a normal user-space
application, but I'm not sure what you're point is. My
statement that printing PDF doesn't depend on Acrobat is true
regardless of whether ghostscript is a driver or application.
Internally, the OS is sending the pdf file to the Acrobat PDF
Driver and then it is sent to the printer.
Nope. It's usnig the foomatic print filters which in turn use
ghostscript to render PDF.


What I mean is that the pdf file is sent to a pdf driver (some
program to interpret it)... In your case is ghostscript, and
in my case is Acrobat.


That's not a driver. At least not in my world. Drivers live
in kernel space. Acrobat and ghostscript are just applications
that run in user-space.
No you just need a good printing system. CUPS + foomatic works
great for me. It knows what to do with postcript, text, PDF,
dvi, and a whole boatload of other fileformats that I don't
ever use.


CUPS + foomatic are the whole megadriver... So it's just a
manner of saying PDF Driver for my study case.


You're use of the word "driver" is one with which I'm not
familiar. But I don't really "do windows" so it's probably a
Widnowism.
Really thanks for all the information :) I didn't know about
Ghostscript.


I'm sure you can use ghostscript to do the same thing under
Windows (render PDF into the raster format preferred by your
printer), but I've no idea how one would go about it.

--
Grant Edwards grante Yow! Hmmm... a CRIPPLED
at ACCOUNTANT with a FALAFEL
visi.com sandwich is HIT by a
TROLLEY-CAR...
Jul 19 '05 #11

P: n/a
"dcrespo" <dc*****@gmail.com> writes:
Hi Grant Edwards...

Your solution requires a previous installation of Acrobat. Internally,
the OS is sending the pdf file to the Acrobat PDF Driver and then it is
sent to the printer. So you have to have Acrobat installed. Don't you?
No, you don't. My print system does that, and I don't have acrobat
installed. I have ghostscript installed, which includes pdf2ps - which
handles this particular translation.
This is what exactly I need to do:
Generate an invoice of 216cm width and 93cm height (1/3 of the height
of a letter paper size), and print it respecting these dimensions. So,
when I print this page on a dot matrix printer, it stops at those 93cm
of height for continuous printing.


Ok, I'm a masochist. When I have problems like this (i.e. - printing
CD labels, addressing envelopes, etc) I just have the python generate
raw postscript. That gives you more than enough control over the
output to solve the problem. Integrating it with a GUI is another
matter, though.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 19 '05 #12

P: n/a
> You're use of the word "driver" is one with which I'm not
familiar. But I don't really "do windows" so it's probably a
Widnowism.


It could be that he means that creating PDFs on windows is done using a fake
printer that will produce the pdf when being printed to - and that fake
printer is implemented as a driver.

And traditionally in printing one often speaks of printer drivers - even if
they are mere filters that can't be considered drivers in the kernel driver
way.
--
Regards,

Diez B. Roggisch
Jul 19 '05 #13

P: n/a
On 2005-04-23, Diez B. Roggisch <de*********@web.de> wrote:
You're use of the word "driver" is one with which I'm not
familiar. But I don't really "do windows" so it's probably a
Widnowism.


It could be that he means that creating PDFs on windows is
done using a fake printer that will produce the pdf when being
printed to - and that fake printer is implemented as a driver.

And traditionally in printing one often speaks of printer
drivers - even if they are mere filters that can't be
considered drivers in the kernel driver way.


I think it's the latter. I believe he wants to know how to
print a PDF file without using any external programs (or
"drivers") like Acrobat Reader or ghostscript that understand
PDF. AFAIK, the only way to do what he wants would be for him
to write a PDF engine in Python that renders PDF into whatever
raw format is understood by his printer.

--
Grant Edwards grante Yow! I'LL get it!! It's
at probably a FEW of my
visi.com ITALIAN GIRL-FRIENDS!!
Jul 19 '05 #14

P: n/a
On Fri, 22 Apr 2005 17:41:22 -0500, Mike Meyer <mw*@mired.org> declaimed
the following in comp.lang.python:
No, you don't. My print system does that, and I don't have acrobat
installed. I have ghostscript installed, which includes pdf2ps - which
handles this particular translation.
Okay, so you've converted one page layout language (PDF) to
another (PS)... To actually print it you still need a RIP. A PostScript
laser printer has the RIP built-in, but consumer level Windows printers
do not have a PostScript RIP -- and some printers don't even have their
own specific RIP built-in ("winprinters" put the RIP into the software
driver that runs on the Windows machine, rather than sending drawing
commands to the printer for rendering).

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 19 '05 #15

P: n/a
> You're use of the word "driver" is one with which I'm not
familiar. But I don't really "do windows" so it's probably a
Widnowism.

It is a windowism but not exclusively ;).
http://www.collaborium.org/onsite/ro...nprinters.html

This is the first link I found that mentioned drivers, but the last
time I installed Linux-Mandrake I saw a document that went into detail
about CUPS and windows printing.
It seems that cups is available for windows( they also use the word
driver )
http://www.cups.org/windows/index.php
Ghostscript for windows available here
http://www.ghostscript.com/
http://www.cs.wisc.edu/~ghost/

Jul 19 '05 #16

P: n/a
Dennis Lee Bieber <wl*****@ix.netcom.com> writes:
On Fri, 22 Apr 2005 17:41:22 -0500, Mike Meyer <mw*@mired.org> declaimed
the following in comp.lang.python:
No, you don't. My print system does that, and I don't have acrobat
installed. I have ghostscript installed, which includes pdf2ps - which
handles this particular translation.

Okay, so you've converted one page layout language (PDF) to
another (PS)... To actually print it you still need a RIP. A PostScript
laser printer has the RIP built-in, but consumer level Windows printers
do not have a PostScript RIP -- and some printers don't even have their
own specific RIP built-in ("winprinters" put the RIP into the software
driver that runs on the Windows machine, rather than sending drawing
commands to the printer for rendering).


RIP? That term is to generic for google to be much use.

If you're saying you need a tool to convert from PDF to whatever the
printer understands, you're right. You can't avoid that. On Unix, PS
is used as the "universal" printer language. Unix vendors selling
printers sold PS printers 20 years ago. That's when apsfilter showed
up on the scene, automatically converting everything to PS to send it
to the printer. (These days, magicfilter is a much better tool than
apsfilter, though it's harder to install). That's why a "competent"
printer installation these days will include ghostscript (or something
equivalent) to drive the printer, and why my primary printer speaks
PostScript.

I disagree with your description of WinPrinters. Those are printers to
stupid to handle flat ASCII, so your computer has to convert flat
ASCII files to postscript or some other graphics format before you can
print them. (This is where magicfilter beats apsfilter - apsfilter
converts ASCII to PS to graphics images, whereas magicfilter can pass
the text straight through. This has caused apsfilter to fail on some
systems where magicfilter would work like a charm). Such printers
typically only come with drivers for Windows, and are completely
useless - unable to even print flat ASCII text - on other systems,
hence the moniker "WinPrinters". Non-winprinters can be used to print
flat ASCII without a driver of any kind. GhostScript now includes
graphics drivers for several winprinters.

The only way to have Python render PDF (or PS, or JPEG, or any other
graphics format) without a "driver" of some kind is to write the
driver in Python. That's a pretty silly thing to want to do. For one
thing, the performance will probably suck. For another, there are lots
of drivers already written that you can use.

The only thing better than writing it in Python is finding that
someone else has already written it.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 19 '05 #17

P: n/a
On 2005-04-23, Mike Meyer <mw*@mired.org> wrote:
No, you don't. My print system does that, and I don't have
acrobat installed. I have ghostscript installed, which
includes pdf2ps - which handles this particular translation.

Okay, so you've converted one page layout language
(PDF) to another (PS)... To actually print it you still need a
RIP. A PostScript laser printer has the RIP built-in, but
consumer level Windows printers do not have a PostScript RIP
-- and some printers don't even have their own specific RIP
built-in ("winprinters" put the RIP into the software driver
that runs on the Windows machine, rather than sending drawing
commands to the printer for rendering).


RIP? That term is to generic for google to be much use.


Raster Image Processor. It renders postscript into a raster
image at the proper image.

--
Grant Edwards grante Yow! If this is the DATING
at GAME I want to know your
visi.com FAVORITE PLANET! Do I get
th' MICROWAVE MOPED?
Jul 19 '05 #18

P: n/a
On Sat, 23 Apr 2005 17:31:22 -0500, Mike Meyer <mw*@mired.org> declaimed
the following in comp.lang.python:

RIP? That term is to generic for google to be much use.
Raster Image Processor -- on a PostScript compatible laser
printer, this is the software and computer that converts PostScript
programs into the actual bitmap needed to print the page. Used to cost
extra to get PostScript capability on top of the printer native (HP PCL,
for example). Normally it runs inside the printer itself.
I disagree with your description of WinPrinters. Those are printers to
stupid to handle flat ASCII, so your computer has to convert flat
IE, absolutely NO RIP at all. Those that handle plain ASCII
still have a RIP to convert ASCII bytecodes to bit patterns for the
printhead.
-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 19 '05 #19

P: n/a
>>>>> "Diez B. Roggisch" <de*********@web.de> (DBR) wrote:
You're use of the word "driver" is one with which I'm not
familiar. But I don't really "do windows" so it's probably a
Widnowism.
DBR> It could be that he means that creating PDFs on windows is done using
DBR> a fake printer that will produce the pdf when being printed to - and
DBR> that fake printer is implemented as a driver.


But that is about creating a PDF file, whereas the OP was speaking about
printing an existing PDF file, For that you need a PDF interpreter, not a
PDF printer driver.
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: pi**@vanoostrum.org
Jul 19 '05 #20

This discussion thread is closed

Replies have been disabled for this discussion.