PDF Printing support from Python

D

dcrespo

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

Grant Edwards

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

dcrespo

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
 
H

Harry George

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

Grant Edwards

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

Peter Herndon

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
 
J

John J. Lee

dcrespo said:
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
 
D

dcrespo

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
 
D

dcrespo

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

Grant Edwards

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

Mike Meyer

dcrespo said:
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
 
D

Diez B. Roggisch

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

Grant Edwards

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

Dennis Lee Bieber

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

--
 
M

M.E.Farmer

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/romania/UTILS/Printing-HOWTO/winprinters.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/
 
M

Mike Meyer

Dennis Lee Bieber said:
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
 
D

Dennis Lee Bieber

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.


--
 
P

Piet van Oostrum

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.
 

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,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top