Raspberry Pi Printer server for LabelWriter


So I have finally come around and started playing with a Raspberry Pi. If you dont know what it is, its a one card arm mini computer, read more at raspberrypi.org. What i tried to accomplish here was to get the pi to work as remote accessible printer server for a Dymo LabelWriter 450.

The goal was to build a web application that could be used from a tablet and on a click on a button in the webapp ui send a request to the pi with a number of paramterers that would for two labels and be printed. The whole thing used a a checkin system for children whit a label for the child and the parent dropping of the child.


After some thouhts i desicided to build the system with the following components and parts:

  • Dymo LabelWriter 450
  • Raspberry Pi, model B with Rasbian Wheezy
  • Apache server (with PHP) on the raspberry reciving the printing requests
  • C++ application on the raspberry doing the actual printing

Getting the printer up and running

Install cups libraries and other necessary libraries to build

pi@raspberrypi ~ $ sudo apt-get install libcups2-dev libcupsimage2-dev g++ cups cups-client

Download Dymo SDK and install the drivers

Download the Dymo LabelWriter SDK for Linux located at http://sites.dymo.com/DeveloperProgram/Pages/LW_SDK_Linux.aspx

pi@raspberrypi ~ $ wget http://download.dymo.com/Download%20Drivers/Linux/Download/dymo-cups-drivers-1.4.0.tar.gz

Now we need to unpack, configure and install the drivers. This is done with the autoconfigure file that is packed with the sdk. Change directory to the unpacked foleder and run ./configure

pi@raspberrypi ~ $ tar xvf dymo-cups-drivers-1.4.0.tar.gz
pi@raspberrypi ~ $ cd dymo-cups-drivers-
pi@raspberrypi ~/dymo-cups-drivers- $ sudo ./configure
pi@raspberrypi ~/dymo-cups-drivers- $ sudo make
pi@raspberrypi ~/dymo-cups-drivers- $ sudo make install

That is everything to get the drivers for the printers installed on the system.

Add the printer

To use the printer, we need to add it in the system first, this is easiest done with cups webadmin. And since the raspberry is only aceessed remote with ssh, we need to install a command line based web browser , I’m using links2. You could use the graphical interface as well. But since the rasperry is going to be a embedded system i’ll do everything with command line.

pi@raspberrypi ~ $ sudo apt-get install links2

And the we need to add the pi user to the printer admin group to be allow to login to the printer admin.

pi@raspberrypi ~ $ sudo usermod -a -G lpadmin pi

Navigate to http://localhost:631/admin with links2

pi@raspberrypi ~ $ links2 http://localhost:631/admin

Select “Add printer”.

Log in with pi user. Default user pi and password raspberry.

In the list of local printers, the “Dymo LabelWriter 450” should appear, mark and continue.

cups_add_printerGive printer a name and description, and continue.

Select the Dymo LabelWriter 450 drivers if found. otherwise you need to locate the file that make install created earlier.

cups_manageThat should be everything for the printer. To verify, go the admin interface and click Manage Printers ant the LabelWriter should appear in the list.

The Code

The printing application

So I built the printing application in c++ from the example code supplied by DYMO.
The includes used for the application, some standard c++ libraries and the cups libraries:

#include <iostream>
#include <cups/cups.h>
#include <cups/ppd.h>
#include <string>
#include <stdio.h>
#include <map>
#include <exception>

This code lists all printers and can be useful to see if your program can find the LabelWriter.

int i;
cups_dest_t *dests, *dest;
int num_dests = cupsGetDests(&dests);
for (i = num_dests, dest = dests; i > 0; i --, dest ++)
  if (dest->instance)
    printf("%s/%s\n", dest->name, dest->instance);

The actual printing does not require that much code. PrinterName is a string with the name of the LabelWriter you chose when you added it before. ImageName is a string with image to be printed, for me it’s a png image that is generated by the web server in the next section.

int num_options = 0;
cups_option_t* options = NULL;

num_options = cupsAddOption("PageSize", "w167h288", num_options, &options);
num_options = cupsAddOption("scaling", "100", num_options, &options);
cupsPrintFile(PrinterName, ImageName, "Print Label", num_options, options);
cupsFreeOptions(num_options, options);

The options for the PageSize parameter can be found in the lw450.ppd file (/dymo-cups-drivers- It lists all paper types and sizes available for that printer.


For compiling the application these flags is used:

g++ `cups-config --cflags` PrintLabel.cpp `cups-config --libs` -o PrintLabel

The receiving HTTP server

The web server, running apache with PHP, is just used for receiving remote calls with parameters and generate an image and then execute the previous c++ application  to print that image.

$firstname = $_GET['firstname'];
$id = $_GET['id'];
$fileName = "kid_".$id.".png";
//... (image generation with GD and write image to disk) ...
$printOutput = array();
exec("./PrintLabel " . $fileName, $printOutput, $status);

20 Replies to “Raspberry Pi Printer server for LabelWriter”

  1. How fast is this printing method? How long does it take to print out a label?
    I’m using cups with thermal printer (Star TSP100) and it take aproximately 5 seconds for an image with lp command.
    Thank you!

  2. I’m currently doing 2 consecutive print calls with one click. And from the click on the button on the webpage it normally takes approx 7 seconds until both labels are printed. I have noticed times up to 12 seconds on rare occasions though.

  3. May I ask what header you used for the main method? Can’t seem to get it rigiht..

  4. Thanks alot, was able to get it to work with that! 🙂

    Now to write a decent image creator ^^

  5. installing the SDK might need this cups library:
    sudo apt-get install libcups2-dev
    sudo apt-get install libcupsimage2-dev

  6. I think I have that in the first command under the section “Install cups libraries and other necessary libraries to build”

  7. *cough* links .. great tool indeed, but if possible I prefer ssh -L. 😉

  8. sudo apt-get install g++ to get what is needed.

    And then I used a Makefile to compile with the following:
    g++ `cups-config –cflags` PrintLabel.cpp `cups-config –libs` -o PrintLabel;

  9. I am new to raspberry pi and I need to print dymo label from iPAD with the help of raspberry pi. I Have compile C++ code also create object file of raspberry pi , but next thing to do call executable from PHP, can you please tell me what are the parameters you have passed to the C++ code and what kind of label is printed from Dymo printer? We need to print dymo label with barcode. Can you please help us to do that ?

  10. Hi, I’m have a python code running which polls an API and fetches some data in json format.

    once i get something i wanted to generate a QR code image and pass it to the DYMO.

    I’m trying to run your c++ programm from my py code, but there is a problem on passing $fileName

    My question, what data for $fileName your program needs? A saved png file on filesystem or base type qr or png instance, which i try create with python qrcode lib?

  11. Hi

    This is currently how I call the compiled C++ program from PHP, where $filename containes the file path to the generated png image:

    $command = base_path() . '/PrintLabel ' . $filename;
    exec($command, $printOutput, $status);

  12. Hi,
    I tested this solution and thank you. My problem is the time between 2 execution of print a label is very long ( > 6 seconds) if i run successively 2 print command (the same with lp command line ). How can i do two reduce time between two prints.
    Thank you.

  13. Can I call this application with text to print an address label? Like: PrintLabel “line1”, “line2”, “line3”

    I’ve written an application in Python to extract addresses from an email that I send myself while out on the road.

    I’m trying to send these these addresses to the label printer as they come in but am having a rally hard time.

  14. Hi, I’m attempting to follow your instructions on Raspbian Stretch but I can’t compile the CUPS drivers. The make command is failing with pages of errors and warnings… Here’s a sample. Any idea what’s wrong?

    In file included from raster2dymolw.cpp:37:0:
    ../common/CupsFilter.h: In member function ‘int DymoPrinterDriver::CCupsFilter::Run(int, char**)’:
    ../common/CupsFilter.h:135:10: warning: ‘template class std::auto_ptr’ is deprecated [-Wdeprecated-declarations]
    std::auto_ptr H;
    In file included from /usr/include/c++/6/memory:81:0,
    from raster2dymolw.cpp:28:
    /usr/include/c++/6/bits/unique_ptr.h:49:28: note: declared here
    template class auto_ptr;
    In file included from raster2dymolw.cpp:37:0:
    ../common/CupsFilter.h: In member function ‘void DymoPrinterDriver::CCupsFilter::InitDocument(const char*)’:
    ../common/CupsFilter.h:218:3: error: ‘ppd_file_t’ was not declared in this scope
    ppd_file_t* ppd = ppdOpenFile(getenv(“PPD”));
    ../common/CupsFilter.h:218:15: error: ‘ppd’ was not declared in this scope
    ppd_file_t* ppd = ppdOpenFile(getenv(“PPD”));
    ../common/CupsFilter.h:218:46: error: there are no arguments to ‘ppdOpenFile’ that depend on a template parameter, so a declaration of ‘ppdOpenFile’ must be available [-fpermissive]
    ppd_file_t* ppd = ppdOpenFile(getenv(“PPD”));
    ../common/CupsFilter.h:218:46: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
    ../common/CupsFilter.h:228:22: error: there are no arguments to ‘ppdMarkDefaults’ that depend on a template parameter, so a declaration of ‘ppdMarkDefaults’ must be available [-fpermissive]
    ../common/CupsFilter.h:234:59: error: there are no arguments to ‘ppdMarkOption’ that depend on a template parameter, so a declaration of ‘ppdMarkOption’ must be available [-fpermissive]
    ppdMarkOption(ppd, Options[i].name, Options[i].value);
    ../common/CupsFilter.h:238:44: error: there are no arguments to ‘cupsMarkOptions’ that depend on a template parameter, so a declaration of ‘cupsMarkOptions’ must be available [-fpermissive]
    cupsMarkOptions(ppd, OptionCount, Options);

  15. Since my last post I realised you can simply do this to install the drivers:

    sudo apt-get install printer-driver-dymo

Leave a Reply

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