Re: [Tutor] Printing from python
> is there another way to print a PDF form python? > > My problem is a PDF which is printed well by evince, but not with lp, > even not out of python using > > os.system("lp some_options file.pdf") > > Later on I have to build the PDF in a python program (using reportlab) > and then print it, even from the python program. I have done this several times before -- generating a pdf with python using reportlab and then printing the result by handing it to lpr. (Not sure what exactly is the difference between lp and lpr, but from a bit of research, it looks like either one should do the job.) The first thing you need to do is make sure that you can print the file from your regular shell (not python) using your chosen print command. If that does not work, python is not going to do anything magical. If you are having trouble with that, it is more of a question for the mailing list supporting your chosen operating system. Once you get that working, shelling out from python will be able to accomplish the same task. (The one possible gotcha is finding the correct path to the file. I think I tended to use full paths to everything to make sure that the correct things would be found.) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing from python
Ulrich Goebel writes: > So I look for a (nice documented) library which give access to the > CUPS API or something else to print the PDF from python. > > Any help is welcome! The problem isn't really one to be solved within your program, IMO. Printing is implemented as a service at the operating system (OS) level. Once you have a document in a form suitable for sending to a printer (such as a PDF), the OS is where any problems with the actual printing need to be addressed. Also, since it is implemented at the OS level, you're not going to find a solution in a platform-agnostic programming language like Python. The solution, whatever it is, will be highly dependent on the services presented by your specific OS. Of course, once you have a suitable OS service for printing the document, Python can send the document to that service. But at that point, the Python code will be trivially easy: probably invoking an external command via ‘subprocess.call’ or ‘subprocess.check_call’. In short: printing is a problem to be solved via the OS, not via Python. -- \ “We are not gonna be great; we are not gonna be amazing; we are | `\ gonna be *amazingly* amazing!” —Zaphod Beeblebrox, _The | _o__)Hitch-Hiker's Guide To The Galaxy_, Douglas Adams | Ben Finney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing from python
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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing from python
op 14-03-14 12:14, Ulrich Goebel schreef: I just found a hint, the Qt QPrinter Class. I use Qt, so that could be a solution? This would be your best bet, use the tools which are provided. I'm a GTK user and use the GTK printing API to both create and print reports. If you want to use cups, this is a project with Python bindings for cups: https://pypi.python.org/pypi/pycups/1.9.66 Timo Am 14.03.2014 11:40, schrieb Ulrich Goebel: Hallo, is there another way to pritt a PDF form python? My problem is a PDF which is printed well by evince, but not with lp, even not out of python using os.system("lp some_options file.pdf") 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. Any help is welcome! Ulrich ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing from python
On Fri, 2014-03-14 at 11:40 +0100, Ulrich Goebel wrote: > Hallo, > > is there another way to pritt a PDF form python? > > My problem is a PDF which is printed well by evince, but not with lp, > even not out of python using > > os.system("lp some_options file.pdf") Python is deprecating os.system in favour of using the subprocess package. subprocess.call('lp some_options file.pdf', shell=True) or subprocess.call(['lp', *some_options, 'file.pdf') assuming some_options is a sequence of strings, on option per string. > 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. > > Any help is welcome! Debian Sid has packages python-cups and python-cupshelpers which are Python 2 APIs for working with CUPS. Sadly there do not seem to be Python 3 versions of these In Debian, but the package in PyPI is pycups so can be made available to Pytho 3. Also: http://cyberelk.net/tim/software/pycups/ I have not used these yet myself, but I have trying them out on my agenda for later in the spring. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing from python
Am 14.03.2014 11:40, schrieb Ulrich Goebel: is there another way to pritt a PDF form python? sorry, that doesn't make sense. I should say: is there another way ... besides os.system()? -- Ulrich Goebel Paracelsusstr. 120, 53177 Bonn ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing from python
I just found a hint, the Qt QPrinter Class. I use Qt, so that could be a solution? Am 14.03.2014 11:40, schrieb Ulrich Goebel: Hallo, is there another way to pritt a PDF form python? My problem is a PDF which is printed well by evince, but not with lp, even not out of python using os.system("lp some_options file.pdf") 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. Any help is welcome! Ulrich -- Ulrich Goebel Paracelsusstr. 120, 53177 Bonn ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor