HOWTO - Print Labels using LibreOffice


LibreOffice can print labels with data taken from a database. You can use a real database, or you can use a simple text file. In this example, we'll cover how to do it with a simple text file.

Printing labels is a special case of form letter handling. LibreOffice always merges form letter data from database, but it provides a means for you to use simple text files as the source for the database.

Creating a simple text database

Create a folder somewhere and give it a name. That name will be the name of your database. We'll use the example name: "Address labels"

Inside the folder, create one or more plain text (.txt) files. The file names will be the database table names. For printing one set of labels, you only need one table. We'll use the example name: "Christmas list.txt"

The contents of the table files are organized so that each record is one row. The data fields in each record are separated by commas.

The very first row is an exception: Instead of data field values, it has the names of your database table fields. Here's an example:

Walt & Grendel Zorbs,3001 County Road 30,Maple Plain,MN 55359
Dirk and Noxima Babbage,321 Fergus Ave,Cupertino,CA 94920
Mary Lou Feeb,PO Box 518,Watertown,MN 55388-0518
Charlotte & Casper Beelzebub,P.O. Box 307,Watertown,MN 55388
Lucy & Mitch Bludge,2530 E Supernatural Blvd,Mohawk Junction,AZ 85119

Some important points to observe:

You could create additional tables: One for each type of mass mailing project you might need. "College friends.txt", "Enemies.txt", etc.

Creating the LibreOffice database

The LibreOffice database you'll create in this step is a filter: It presents the contents of your text files to clients in database format, but the text files remain your primary data sources. When you edit the text files, your database will change automatically.

Here are the steps to create the LibreOffice database:

Run LibreOffice Base.

Click the radio button "Connect to an existing database".

From the combo box under the button, select "Text".

Press "Next" at the bottom of the window.

In the next panel, click the "Browse" button and navigate to the location of your database folder. Hit "Ok".

Specify the type as "Plain text files (.txt)".

At the bottom of the window, there are some selections for defining the field separators and number formats. The defaults should be ok.

Press "Next"

On the next panel, choose "Yes, register the database for me".

Uncheck "Open the database for editing".

Click "Finish" at the bottom of the window.

When prompted, save your LibreOffice database file in the same folder where you put your tables. You can avoid confusion later by making the file name the same as the folder name for this project. Recall that the folder name is used automatically as the database name.

Editing your database

Unfortunately, you can't use all the nifty database editing tools in LibreOffice Base. To add or change fields, you have to edit your original text files. The good news is that you never have to repeat the steps from the last section or use LibreOffice Base again.

Defining labels

Run LibreOffice Writer.

From the File menu, select "New -> Labels". In the window that pops up, select your database from the Database combo box. Select your table from the Table combo box.

On the left side of the window is a large empty box. This is where you'll define how the table fields are positioned to make a label. You build the label one field at a time. We'll do this step by step for our example. Recall that the field names in the table file were:


From the Database field combo box, choose "Name". Press the big left arrow button text. You'll see this line appear at the top of the label:

<Address Labels.Christmas list.0.Name>

Although obscure and mysterious, you can see that the last part of this field name is "Name" which is what you want. Enter a line break by pressing Enter. From the Database field combo box, select "Address". That will add another line to the label so you now have:

<Address Labels.Christmas list.0.Name>
<Address Labels.Christmas list.0.Address>

Add another line break and choose the field "City". Now you should see:

<Address Labels.Christmas list.0.Name>
<Address Labels.Christmas list.0.Address>
<Address Labels.Christmas list.0.City>

This time, don't enter a line break. Instead, put in a comma and a space after the <...City> line. Then choose "State" from the Database field combo box. Your final result should look like this:

<Address Labels.Christmas list.0.Name>
<Address Labels.Christmas list.0.Address>
<Address Labels.Christmas list.0.City>, <Address Labels.Christmas list.0.State>

Near the bottom right corner of the window, select you label stock using the Brand and Type combo boxes. If you don't find your label type, don't panic. It's easy to define a new one: Choose "user" from the top of the list, get out a good ruler and measure you label sheet. You can save your new label definition and it will become a permanent selection alternative in the list.

Congratulations! You're almost done. Press "New Document" at the bottom of the window.

The first thing you see is a bit disappointing: A big sheet of labels will appear in the LibreOffice Writer document window, but all the labels will look the same: they show the field names you selected. Again, don't panic!

Styling your labels

From the Format menu, select "Styles and Formatting". A new pane will open to the right of your document. Under the caption you'll see a row of icons. Choose the one named "Paragraph Style" (The name will pop-up if you hover over the icon.)

Right-click on "Default Style" and choose "Modify" from the pop-up menu. The next window is full of tabs for changing any aspect of your lable. When you press "Apply", the field names laid out in the document window will change to look like the selected style. (It would be nice if it showed your data instead.)

One style element you almost always need to adjust is on the "Indents & Spacing" tab: Change the "Before text" item value to about 1/8" (0.125") - This will keep your label text away from the left edit of the label, where it might otherwise be cut off by small offsets when the paper goes through the printer.

Keep fussing with the default style and pressing "Apply" until you're satisfied. Then press "Ok" to exit the dialog window.

Selecting records for printing

Choose Print from the File menu.

An alert window will pop that says:

"Your document contains address database fields. Do you want to print a form letter?"

Select "Yes".

The Mail Merge dialog window will pop up.

On the left, you'll see a tree view with all your defined databases and tables. (You can resize the whole window to expose all the fields.)

Select the table "Christmas list". A mini-spreadsheet view will appear on the right.

Under the Records title, you'll see a radio cluster where you can choose "All", "Selected records" or a range of records.

To choose individual records, pick them out line by line by ctrl-clicking in the empty box to the left of each row.

To choose all the records, I've found that it's safest to actually select all the records using the mouse: Select the first row and shift-select the last row.

When you've got what you want, press "OK"

Selecting print options

The next window will display the usual print dialog.

First, select the destination printer.

Next, press the "Properties" button:

What you see here depends somewhat on the brand of printer and the driver software you've installed. What you need to accomplish here is selecting the paper type and paper source.

Label stock works best when fed from the printer's bypass tray. Select this from the "Paper Source" combo box.

From the "Media type" combo box, select "Labels".

Hit "OK"


From the last step, you will return to the main printer dialog window. You should see a mini-page view on the left side: Confirm that the records you want to print are displayed on the form.

Put a sheet of label stock in the bypass tray of the printer. On my printer, it has to go in face down.

Back at the computer, press "OK" again.

If the Gods are with you, your labels will print perfectly.