Ever tire of laying out a sheet of address labels in OpenOffice.org or Word templates when you’re in a hurry? Karl Fogel’s LabelNation may be able to help. It is a small free software tool that whips out printer-ready label layouts from the command line. All you do is put the addresses in a plain text file and run LabelNation; the output is a standard PostScript file. And it’s not just fast; as a command-line tool it is easily integrated into scripts or other automated workflows.
LabelNation is written in Python. You can download the latest package from the project’s Web site. The package includes the labelnation executable (which will run on any platform with Python installed), plus instructions and a folder full of examples. LabelNation comes pre-configured to handle more than 50 different standard label sheets from Avery and other manufacturers, but you can also specify your own layouts if needed.
Basic usage requires calling the labelnation script with five arguments: labelnation -t labeltype -l -d "delimiter" -i inputfile -o outputfile. For example, labelnation -t avery5661 -l -i addresses.txt -o mylabels.ps.
The -l switch tells LabelNation that the input file contains lines of text (it can also take PostScript input for more complex variations by substituting the -c flag, but this is for advanced users). The label types available for -t include standard 4- to 80-label-per page layouts on both letter sized and A4 paper. LabelNation will print out a complete list of available options if you run labelnation --list-types.
The delimiter specified by the -d switch tells LabelNation what separates the addresses between the labels in your input file. So if you use —- as a delimiter, your input file might contain:
123 Fake Street, Apt 5E
New York, NY 10201
456 Faker Avenue
New York, NY 10211
123 Fake Street, Apt 5D
New York, NY 10201
… and so on; you would then call LabelNation with -d "----" as an argument. As you can see, the address text is indented; this is to allow you the flexibility to place addresses as close to the edge horizontally as you see fit — you can add as much or as little as you like, which can be handy if you will be printing labels with a pre-printed border or logo. Other than spacing ans the address delimiter, no special formatting is required of the input. LabelNation supports the Latin-1 or ISO 8859-1 character set, including all of the accented characters. It also automatically adjusts the font size to fit the label type specified by -t.
If you are new to LabelNation, the program allows you to get used to spacing and other formatting issues with the optional --show-bounding-box switch. This will produce output with a black line outlining each label; that way you can print a sample sheet and adjust your spacing before printing your final labels.
If you find that your labels are consistently misaligned with LabelNation’s output, perhaps due to printer feed differences, you can easily adjust the margins LabelNation uses with the --bottom-margin and --left-margin arguments. First, run labelnation --show-parameters for the label type in question. For example, labelnation --show-parameters -t avery5661 returns:
If the left margins are too small, simply try adding a few points by adding --left-margin 32 to your command.
You don’t have to print a full sheet of labels at a time, either. If you only have a few to print, you can reuse a partial sheet of labels and tell LabelNation where on the sheet to start printing with --first-label n. The count starts in the bottom left-hand corner and goes up column by column, like so:
4 8 12
3 7 11
2 6 10
1 5 9
… reflecting the number of labels in the specified type.
Despite all of the flexibility described above, LabelNation is capable of doing much more if you are willing to learn. First of all, you can create your own label types if the labels you need to work with are not in the predefined list. All you have to do is create a text file containing the parameters of your label sheet, in the plain-text format reported by LabelNation when you call the --show-parameters switch. The margins, label width and height, and spacing are all measured in points. With your file saved, just tell LabelNation to use it with the -p flag, such as labelnation -l -i myinputfile.txt -o myoutput.ps -p mynewparameters.txt
The more adventuresome should explore the -c flag, which tells LabelNation that the input file contains PostScript, not plain text. PostScript is a complex and powerful language, but the LabelNation Web site reports that users have had success through trial and error with creating graphics and other features using -c.
Finally, like most good command-line utilities, LabelNation can be used in scripts to automate label generation. For example, you could export names and addresses from your address book to plain text files, then write a bash script to quickly produce printer-ready mailing labels from them with LabelNation. Even better, you could specify a dash as the output file argument (i.e., -o -) — that tells LabelNation to send its output to stdout. You could pipe that output directly to the printer with labelnation -t avery5661 -l -i myinput.txt -o - | lpr … and print your labels directly, without the intermediate PostScript stage.
By Nathan Willis
Visit Worldlabel.com for all popular size labels