Printing forms and labels in Python

M

Monte Milanuk

Hello,

I'm still a relative newbie to python, so I apologize if this is covered
in detail somewhere and I missed it.

I have a program or two that I want to work on once I get more
proficient with python and sqlite and tkinter/wxpython. One of the big
'features' of those programs I want to make is going to be printing out
match results (scores) from a competition along with competitor names
and other pertinent information. Currently most people are doing this
in Excel, though there is one (old) DOS program written in BASIC that
not only prints the match results and the reports for the sanctioning
body, but also prints labels via a Dymo Label maker.

I realized today that one thing I have never seen covered in any Python
tutorial is how to format and print things to a physical printer. I did
a little bit of searching and didn't come up with much... either I'm
really not using the right search terms, or physical printing is a black
hole/art...?

TIA,

Monte
 
M

Mel

Monte said:
I realized today that one thing I have never seen covered in any Python
tutorial is how to format and print things to a physical printer. I did
a little bit of searching and didn't come up with much... either I'm
really not using the right search terms, or physical printing is a black
hole/art...?

It's massively device-specific...

What I did when I needed precision printing was have my Python programs
generate PostScript code, then run that through ghostscript to do the actual
printing. PostScript was designed to control printers down to the pixel.
It's possible to streamline the production run by running ghostscript using
the subprocess module. Of course you have to learn PostScript to do this,
which is not really simple.

The other possibility that I'm aware of might be to get a graphics package
(the one built in to wx is the one I'm familiar with) and set up your
printable text and graphics in a appropriate device context suitable for
your printer.

Mel.
 
A

Anssi Saari

Monte Milanuk said:
Hello,

I'm still a relative newbie to python, so I apologize if this is
covered in detail somewhere and I missed it.

I have a program or two that I want to work on once I get more
proficient with python and sqlite and tkinter/wxpython. One of the
big 'features' of those programs I want to make is going to be
printing out match results (scores) from a competition along with
competitor names and other pertinent information. Currently most
people are doing this in Excel, though there is one (old) DOS program
written in BASIC that not only prints the match results and the
reports for the sanctioning body, but also prints labels via a Dymo
Label maker.

I actually looked into label printers recently. It seems that at least
the cheaper models from Brother and Dymo accept a bitmap in specific
dimensions and they print it pixel exactly. Very simple, in other
words. But different printers need different formats, which is why
there are printer drivers. I'd assume the DOS program you mention
supports a very specific Dymo printer?

Anyways, for operating systems using CUPS for printing (that would be
Mac OS X, Linux, *BSD at least), there seems to be pycups which wraps
the CUPS API.

From a quick study of
http://timgolden.me.uk/python/win32_how_do_i/print.html, it looks like
in Windows you can just use the win32 APIs for printing, which is
hard. An easier alternative seems to be using PIL to generate a DIB
with your data in it and printing that.
 
M

Monte Milanuk

I actually looked into label printers recently. It seems that at least
the cheaper models from Brother and Dymo accept a bitmap in specific
dimensions and they print it pixel exactly. Very simple, in other
words. But different printers need different formats, which is why
there are printer drivers. I'd assume the DOS program you mention
supports a very specific Dymo printer?

Honestly, I don't know. The interface of that program usually has me
grinding my teeth within minutes. It was written years ago, and is in
fact now being updated... to a 'new' version of BASIC (still with a
'DOS' interface) only because the existing version will not run on
anything newer than Win XP due to memory issues (assuming I understood
the problem correctly). I was looking today and see that Dymo makes a
SDK available that is supposed to be cross-platform (more specifically,
download the SDK for the platform you want to use), but given the age of
this setup... I'm guessing it was probably hard-coded to a particular
device.

The labels are sliding backwards into the 'nice to have' category.
Being able to print out the final results sheets (one or two pages at
the end of the day) is the primary goal at this point.
Anyways, for operating systems using CUPS for printing (that would be
Mac OS X, Linux, *BSD at least), there seems to be pycups which wraps
the CUPS API.

http://timgolden.me.uk/python/win32_how_do_i/print.html, it looks like
in Windows you can just use the win32 APIs for printing, which is
hard. An easier alternative seems to be using PIL to generate a DIB
with your data in it and printing that.

Actually... for the results sheet, the shellExecute method he described
just might work.
 
D

Dennis Lee Bieber

printed. Just insure you have the right port (BTW not as easy as it used
to be).
<heh> As I discovered today, on my laptop...

A Rigblaster P&P unit was assigned COM10... But the freeware
software to handle PSK31 protocol only knew about COM1..COM9.

Seems my bluetooth PCMCIA card -- which hasn't been used in over 6
years [old laptop] had sucked up COM6..COM9 for <something>, FAX, LAN,
Serial emulations, and COM3..COM5 had been absorbed by other stuff (I
suspect the LPI/DSI astrocameras, and my trackball/mouse).

Had to disable the <something> and FAX ports, and luckily the
drivers for the Rigblaster permitted manual selection of a different COM
port... About 15 minutes later manage my first HF QSO... [Disgusting, I
know... My first high frequency radio contact since advancing from
no-code technician wasn't even a voice mode, but computer/digital!]
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top