How do i print to a printer using python?

Frank Buss fb at frank-buss.de
Thu Sep 5 13:45:52 CEST 2002


"G. Willoughby" <never at mind.info> wrote:

> I would really like to know how to do this too, basically i want to
> print to a standard bubblejet print (non postscript) from a Tkinter
> Text widget, any ideas?

Perhaps you can draw a PDF file with Reportlab (http://www.reportlab.com/) 
and printing it. Because you are using Outlook Express, I assume you need 
it for Windows. An example:

from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4
c = canvas.Canvas('c:\\tmp\\test.pdf', pagesize=A4, bottomup=0)
c.setFont('Helvetica', 14)
c.drawString(10, 20, 'Hello World!')
c.save()

If you want direct printing, without user interaction and you know the 
path of the Acrobat Reader, you can use this line:

system('"C:\\Programme\\Adobe\\Acrobat 5.0\\Reader\\AcroRd32.exe" /p /h c:
\\tmp\\test.pdf')

Perhaps it's easier with the ShellExecute command, because then you don't 
need to know the path of AcroRd32.exe, but then you need this, if you 
don't have ActiveState Python installed:
http://starship.python.net/crew/mhammond/win32/Downloads.html

If you just want to show the user the page and let the user decide to 
print or close the document, this lines are sufficient:

from os import startfile
startfile('c:\\tmp\\test.pdf')

-- 
Frank Buß, fb at frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de



More information about the Python-list mailing list