[Tutor] Printing from python

Alan Gauld alan.gauld at btinternet.com
Fri Mar 14 20:55:14 CET 2014


On 14/03/14 10:40, Ulrich Goebel wrote:

> Later on I have to build the PDF in a python program (using reportlab)
> and then print it, even from the python program.
>
> So I look for a (nice documented) library which give access to the CUPS
> API or something else to print the PDF from python.

I may be mistaken but I don't think CUPS will help you.

PDF documents are effectively programs that have to be interpreted
by a PDF reader of some sort. Some printers have that capability
built in, most require a program such as Acrobat or ghostscript
to do the formatting for them.

I don't think CUPS has an API for rendering PDF directly it
will simply send the PDF direct to a PDF aware printer or take
the image out from a PDF reader and send it to a standard
print driver.

Your Qt solution may support PDF rendering, I don't know Qt,
but its definitely worth pursuing. Failing that you probably
do need to use subprocess to launch ghostscript or similar.
But there is no shame in that, chaining programs together
is standard Unix practice and a sign of good design - one
program does one job.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list