Print a PDF transparently

D

Daniel Crespo

Hi to all,

I want to print a PDF right from my python app transparently. With
"transparently" I mean that no matter what program handles the print
petition, the user shouldn't be noticed about it.

For example, when I want to print a PDF, Adobe Acrobat fires and keep
opened. This is what I don't want to happen (and I thing there are a
lot of people who want this too). So I just want to send the PDF to the
right handler and print it. That's all.

I've seen some things like Adobe's Postscript driver that can read a
PDF, or Ghostscript, but I still don't know how to use it.

Any help for printing a PDF transparently?

Thank you

Daniel
 
I

infidel

Daniel said:
Hi to all,

I want to print a PDF right from my python app transparently. With
"transparently" I mean that no matter what program handles the print
petition, the user shouldn't be noticed about it.

For example, when I want to print a PDF, Adobe Acrobat fires and keep
opened. This is what I don't want to happen (and I thing there are a
lot of people who want this too). So I just want to send the PDF to the
right handler and print it. That's all.

I've seen some things like Adobe's Postscript driver that can read a
PDF, or Ghostscript, but I still don't know how to use it.

Any help for printing a PDF transparently?

The only way I was able to find to do it (for free) was to install
GhostScript and GSView. GSView comes with GSPrint.exe, which you can
call with a regular command line to send PDF files to a printer. It
uses GhostScript for you behind the scenes because GhostScript is not
exactly the friendliest program to work with.
 
C

Cameron Laird

Hi to all,

I want to print a PDF right from my python app transparently. With
"transparently" I mean that no matter what program handles the print
petition, the user shouldn't be noticed about it.

For example, when I want to print a PDF, Adobe Acrobat fires and keep
opened. This is what I don't want to happen (and I thing there are a
lot of people who want this too). So I just want to send the PDF to the
right handler and print it. That's all.

I've seen some things like Adobe's Postscript driver that can read a
PDF, or Ghostscript, but I still don't know how to use it.

Any help for printing a PDF transparently?
.
.
.
Yes, but it's never going to be easy. People have worked on this for
years ...

First, what platforms and printers interest you? Are you only interested
in Linux-connected-to-PostScript-capable-printers, or do you want to do
Windows and Mac, and ...?

Also, there are likely to be licensing considerations sooner or later.
Start thinking about your situation in that regard.
 
G

Grant Edwards

I want to print a PDF right from my python app transparently. With
"transparently" I mean that no matter what program handles the print
petition, the user shouldn't be noticed about it.

This works for me:

system("lpr whatever.pdf")

Or alternatively,

os.popen("lpr"."w").write(myBigStringContainingPDF)
For example, when I want to print a PDF, Adobe Acrobat fires and keep
opened. This is what I don't want to happen (and I thing there are a
lot of people who want this too). So I just want to send the PDF to the
right handler and print it. That's all.

See above.
 
D

Daniel Crespo

Hi, Thanks for all the answers.

My main purpose is to print on Windows systems (98,2000,XP) and permit
to print pages of 1/3 of a letter height, and make the printer to stop
at that point (in dot matrix printers). When I have a PDF with that
paper size and send it to print from Acrobat, it prints and stops
perfect (in Win98, I have to create a custom form consisting of that
paper size). The problem is that PDF files have to be handled by
external applications, or non-free drivers.

Based on all this, I have been investigating about postscript files. I
realize that printers do handle this language, so I think if I have a
..ps file and send it directly to the printer, it should do the job,
right? (this is certainly a question) If the answer is True, no matter
in what platform I am, if I send the same .ps to the printer, it should
print the same result.

And if all of these is true, then, my problem reduces to generate the
..ps file.

Comments please

Daniel
 
D

Diez B. Roggisch

Based on all this, I have been investigating about postscript files. I
realize that printers do handle this language, so I think if I have a
.ps file and send it directly to the printer, it should do the job,
right? (this is certainly a question) If the answer is True, no matter
in what platform I am, if I send the same .ps to the printer, it should
print the same result.

No. There are PostScript-Printers out there - but your off-the-shelf InkJet
isn't, and that's the reason why there usually has to be some sort of
driver in-between. Which is either GS or, in case of PDF, the acrobat-* or
any other PDF-printer-emulator.

maybe you can go down the rocky road of automation here, remote-controlling
acrobat reader. But I doubt that it wouldn't at least flash up with its
window for as long as the printing lasts.

Diez
 
D

Dennis Lee Bieber

Based on all this, I have been investigating about postscript files. I
realize that printers do handle this language, so I think if I have a
.ps file and send it directly to the printer, it should do the job,
right? (this is certainly a question) If the answer is True, no matter
in what platform I am, if I send the same .ps to the printer, it should
print the same result.
Only if the PRINTER has PostScript built-in... Practically no
"desktop" printer (the common inkjets you find sold with computers) have
PostScript engines. All of these would require a software
PostScript->printer-language driver module (old HPs used had something
called PCL [printer control language] as I recall). "WinPrinters" have
nothing -- they can't even do ASCII text without software (all a
WinPrinter understands is pure bitmaps, the driver has to render a print
image in memory).

Larger, office-size, laser printers may have PostScript.
And if all of these is true, then, my problem reduces to generate the
.ps file.

From a PDF? PDF basically is a form of PostScript optimized for
screen display (as I recall, a lot of the PostScript multi-character
commands became single characters... "xpos ypos move" -> "xpos ypos m")
and for hyperlinking (so the table of contents is live)

Adobe has a Windows PostScript driver for free; but that still
leaves you out... It works as a "printer" but you still have to run the
normal application to print /to/ it -- and that is what you say you
don't want! http://www.adobe.com/support/downloads/detail.jsp?ftpID=1500


--
 
C

Cameron Laird

No. There are PostScript-Printers out there - but your off-the-shelf InkJet
isn't, and that's the reason why there usually has to be some sort of
driver in-between. Which is either GS or, in case of PDF, the acrobat-* or
any other PDF-printer-emulator.

maybe you can go down the rocky road of automation here, remote-controlling
acrobat reader. But I doubt that it wouldn't at least flash up with its
window for as long as the printing lasts.

Diez

Right. It's possible, barely, to achieve the desired result
with Ghostscript, but it's going to take considerable care in
installation and configuration. We do this sort of thing, but
only on hosts we control; the thought of full-blown "producti-
zation" (let alone the licensing) intimidates me.
 
E

EShames

Hi to all,

I want to print a PDF right from my python app transparently. With
"transparently" I mean that no matter what program handles the print
petition, the user shouldn't be noticed about it.

For example, when I want to print a PDF, Adobe Acrobat fires and keep
opened. This is what I don't want to happen (and I thing there are a
lot of people who want this too). So I just want to send the PDF to
the right handler and print it. That's all.

I've seen some things like Adobe's Postscript driver that can read a
PDF, or Ghostscript, but I still don't know how to use it.

Any help for printing a PDF transparently?

Thank you

Daniel

You may find that RedMonEE is a useful piece to your puzzle. I find it
to be stable and quite invaluable.

http://www.is-foehr.de/
 
D

Daniel Crespo

Adobe has a Windows PostScript driver for free; but that still
leaves you out... It works as a "printer" but you still have to run the
normal application to print /to/ it -- and that is what you say you
don't want! http://www.adobe.com/support/downloads/detail.jsp?ftpID=1500

Yes, I've seen it, but that's it: another program that I have to
install, which I want to avoid.

I'd be happy if I just do "printer.Print(file.pdf/.ps)" and walá, the
printing just starts (in 98,2000,XP... sounds like a dream), without
having another window opened. If it opens, but then closes, it's
perfect too. I have tried installing Ghostscript, and having a .ps when
I order that file to print, it does the job. The thing here is that I
have to install it.

All this has to be easilly installed (with InnoSetup, for example),
because I have to install it on 70 offices. So I can't leave it to
another installation process. All of these offices have a dot matrix
printers Epson LX-300, which has PostScript level 3 built-in.

Where can I find how to send a .ps directly to the printer?

Daniel
 
B

bonono

Daniel said:
Yes, I've seen it, but that's it: another program that I have to
install, which I want to avoid.

I'd be happy if I just do "printer.Print(file.pdf/.ps)" and walá, the
printing just starts (in 98,2000,XP... sounds like a dream), without
having another window opened. If it opens, but then closes, it's
perfect too.
I have done such thing a few years back, just use the file association
and the "print/printto" action. All you need is to have Acrobat
installed. You can try it by right click on the desktop on a .PDF file
and select print. A modeless dialog would still be visible but would
close itself. This was using ancient Acrobat Reader.

You need to read the WIN32 API(I faintly remembered about Shell
something) that tells you how to do it programmatically(I used C).
All this has to be easilly installed (with InnoSetup, for example),
because I have to install it on 70 offices. So I can't leave it to
another installation process. All of these offices have a dot matrix
printers Epson LX-300, which has PostScript level 3 built-in.

Where can I find how to send a .ps directly to the printer?
Again, in the WIN32 API and unfortunately 98 and NT family has
completely different mechanism.
 
D

Daniel Crespo

Have you seen this?
http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html
In particular, the section on using win32print directly.

Yes, I have. The problems is that an external program is launched for
handling the file and print it. In the case of PDF, acrobat is
launched. In the case of PS, Ghostview is launched. When printing a
PDF, acrobat keeps alive, so the user has to close it manually. On the
other hand, Ghostview is opened, prints the file and closes
automatically. The last one is which I find the best for me, until now,
(because the Ghostview closes automatically). If I decide to go this
way, my problem then is to transform a pdf to ps, or generate a ps
directly.

For further information on what I want, please, refer to my first two
posts in this topic.

Any other help?

Thank you very much
 
D

Daniel Crespo

Have you seen this?
http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html
In particular, the section on using win32print directly.

Yes, I have. The problems is that an external program is launched for
handling the file and print it. In the case of PDF, acrobat is
launched. In the case of PS, Ghostview is launched. When printing a
PDF, acrobat keeps alive, so the user has to close it manually. On the
other hand, Ghostview is opened, prints the file and closes
automatically. The last one is which I find the best for me, until now,
(because the Ghostview closes automatically). If I decide to go this
way, my problem then is to transform a pdf to ps, or generate a ps
directly.

For further information on what I want, please, refer to my first two
posts in this topic.

Any other help?

Thank you very much
 
R

Roger Upole

This seems to work ok with acrobat 7 (don't know if it will work
with earlier versions). The only thing I had to tweak was
acrobat's security setting for allowing print via script operations.
I didn't try to figure out how to wait until the print was finished.

hth
Roger


import win32com.client, time
ie = win32com.client.Dispatch('InternetExplorer.Application')
## ie.Visible=1
ie.Navigate('somedocument.pdf')
while ie.Busy:
time.sleep(1)
ie.Document.printPages(1,3)
 

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,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top