Advanced usage with gLabels: labels/cards Linux/GNU

In the previous post in this series, we looked at the basic design tools used to create labels and business cards with gLabels: the drawing tools, text tools, how they compare to raster- or vector-graphics editors, and the object manipulation tools. We also covered how to print your creations, and what formatting options gLabels provides to make life easier. Chances are, though, that at some point you will need to take advantage of some of gLabels’ more advanced features, such as the ability to do “mail merge” printing, to incorporate readable barcodes, or to edit label templates of your own.

by Nathan Willis


The term “mail merge” usually means printing a set of documents, labels, or envelopes based on a common template so that the generic information in the template is replaced with a unique set of specifics — typically pulled from an external file, such as a comma-separated-value (CSV) text file. That way, you only set up the document once, but can print out hundreds of uniquely-addressed copies.

Obviously this sort of functionality is not limited to use with mail envelopes, so gLabels refers to it by the more general term “document merge.” The official documentation even gives an example using name tags.

To add a document merge to your label design, you must start with configuring the data source. Click on the “Edit merge properties” button on the toolbar, which will open the configuration window. gLabels supports several data formats, including plain text with either tab, colon, or comma delimiters between the fields, VCard address book files, and direct import of address book entries from GNOME’s Evolution email client. Select the appropriate format from the drop-down box, then select the actual file you will use for the merge.

“gLabels can do a document or “mail merge” from several data sources.”

gLabels then loads the contents of the file into the preview pane, both to help you see whether or not the fields are aligned correctly and so that you can check or uncheck specific records for inclusion in the final merge. Check to make sure that each field is correctly displaying the data you expect — including any blanks. If your export skipped a field without data rather than inserting a properly-delimited blank space, it could throw off every other field for that particular record.

When you are satisfied with the structure of your data, click “OK.” It is time to incorporate your document merge placeholders into the label design. You do this by inserting text objects, then inserting special control codes into the display text. The format for a control code is ${FIELD_NAME}. For a typical CSV or plain text data source, gLabels uses simple numbers for the field name, such as ${1} for the first field, ${42} for the 42nd field, and so on. A VCard or Evolution data source would use ${PHONE}, ${SUFFIX} or other appropriately self-explanatory field names provided by the data source itself.

If you select a text object, gLabels’ object properties pane allows you to insert a field control code with the “Insert merge field” button — the adjacent “Key:” selector is automatically filled with the available field names extracted from the data file, so there is no chance of mis-typing.

When gLabels encounters a blank field in a record, it prints nothing, so (for example) $[FIRSTNAME} ${MIDDLENAME} ${LASTNAME} will not cause an error or an unsightly extra whitespace when printing an entry without a middle name. Nevertheless, you must take an additional precaution to prevent the accidental printing of a blank line in your output. If you are formatting postal addresses of the form:


then you must ensure that ${ADDRESS_LINE_1} and ${ADDRESS_LINE_2} are the only text on their respective lines, including whitespace. If so, gLabels will skip printing the entire line for records missing one of those fields, which is the expected behavior. If, however, there is also a blank space on the same line as ${ADDRESS_LINE_2}, the resulting output will include a blank line.

As long as the control codes remain in place, you can do any other text style manipulation you wish to make your final output appear as desired; there are no limitations on font, color, or other properties. To check the output of your document merge, open the Print dialog and click on the Print Preview button — gLabels will show you the final merged output.

mail merge

“gLabels shows a preview of its merge data import, to check for accuracy.”

If you try a print preview, you will immediately notice that gLabels automatically detects the number of entries in the file and composes its output with the correct number of labels or cards. The same is true for final printing; you do not need to worry about counting the number of merged records. You can, however, select which label position on the sheet to start printing on. This allows you to re-use partially printed sheets of labels.


Another business-friendly feature supported in gLabels is the ability to incorporate barcodes into your label designs. Barcode objects are among the elements you can insert from the toolbar, and like rectangles, ellipses, or images, you have full control over their size, position, and color. Much like a text object, though, you must specify the contents of the code to be created.

“gLabels supports generating barcodes from data.”

When you insert a barcode, the object properties pane displays a “Data” tab. Here you can manually specify the text contents to be rendered in the label as a barcode, or you can link the contents to a field in a document merge. To do the the latter, just select the “Key” radio button, and choose the field of choice from the drop-down menu. As with text objects, gLabels pre-loads the available keys into the drop-down menu, so there is no danger of choosing the wrong one.

The “Style” tab allows you to specify the barcode format to be rendered, and the color in which it will be drawn. gLabels supports a range of different barcode formats — at present a total of 30, including POSTNET, UPC, ISBN, and the 2-D DataMatrix format. The different formats have different capabilities; for example, you can only encode numeric data in POSTNET, because it was created for encoding ZIP codes. If you try to render incompatible data into a barcode, gLabels will write an error message to that effect when it prints or in print preview. Consequently, if you intend to use barcodes for internal usage rather than compatibility with the post office or some other business, brush up on the available formats before selecting one.

 “gLabels allows you to choose from numerous barcode formats.”

You can also use a field from your data source to set the color of the barcode. On the Color setting in the “Style” tab, just click on the “Key” radio button and select the field to be used from the drop-down menu much like you did for “Data.” Acceptable values for a color key include the standard X named colors from /etc/X11/rgb.txt or an RGB hex value formatted much like HTML colors. gLabels can use more significant digits in its hex values, though, so #RGB, #RRGGBB, #RRRGGGBBB, or even #RRRRGGGGBBBB are acceptable formats.


For the vast majority of the print jobs you create with gLabels, the supplied templates will be exactly what you need. On the other hand, if you have to create a curiously-shaped label (perhaps to be cut out of one of the larger label sizes), or if you need to change the dimensions of the generic business card template to fit your design, gLabels can help.

“The template designer steps you through the process of creating a template.”

gLabels templates are written in XML that defines the shape, spacing, margins and other properties of the label or card in question, and provide some metadata useful to the application. System-wide labels like the ones that come pre-packaged in most distros are stored in /usr/share/glabels/, but the program will also look in ~/.glabels, so you can store your custom designs there.

You can consult gLabels’ help documentation for a tutorial on creating templates with a text editor — the process is not that hard; you must define height, width, round-ness of corners, and other properties. An easier option, however, is gLabels’ “Template Designer,” found under the “File” menu. This is a simple GUI wizard that walks you through the steps of defining the required physical properties and metadata.

 “Designing a template is not hard, but requires making some precise measurements.”

To begin with, you must enter a “Brand” and “Part number” for your template — these correspond to a commercial label product; if you are creating a custom template from scratch, you can use any information you find descriptive. You then select the paper size, and the basic shape of the label or card. Of note, gLabels templates require that all labels on a single sheet be the same size, however, gLabels can accommodate templates that use multiple label sizes (such as CD label sheets that include a CD case label) by creating multiple layouts. You simply design with and print them separately.

When you get to the step defining the actual dimensions of each label you can add the “safe area” lines that appear in the label drawing area, and the amount of overprint that can be tolerated without bleeding into adjacent labels on the sheet. The last page of the template designer allows you to specify the layout of the page — how many rows and columns of labels or cards there are, and the distances between them and from the edges of the page. There is a print button that allows you to print or print-preview a test template before you finalize your design.


gLabels undergoes constant development, but over the years it has evolved into an easy to use tool with a deceptively large feature set. Most users may never need to design their own templates, and few will need to incorporate barcodes regularly, but it is nice that the application not only supports these tasks, but makes them simple. On the other hand, almost everyone will have occasion to do a document merge at one time or another, and the robustness of gLabels’ support for this common task shows real code maturity. gLabels manages to make even this potentially complicated task point-and-click simple.

See Part 1 Getting Started with gLabels by Nathan Willis

7 thoughts on “Advanced usage with gLabels: labels/cards Linux/GNU

  1. Grishnakh

    Does it support thermal labels, or only ones printed in a laser/inkjet printer? Something that worked with thermal label printers (like Zebra) would be really helpful.

  2. Vincent Onelli

    I downloaded glabel but I was not able to install.
    ./configure went through OK
    make: returned “no targets specified end no makefile found
    there is and what am I doing wrong?

  3. JohnW

    Second the motion for a simple way to increment the label numeric fields. Ex: Making a series of Tape labels in 3 of 9 format. Looks great otherwise!

Leave a Reply

Your email address will not be published. Required fields are marked *