To be able to use the library DYMO Label software should be installed on the client machines. On Windows version 8.3 or later is required. Version 126.96.36.1992 is available on http://download.dymo.com/download/Win/DLS8Setup.188.8.131.522.exe On Mac version 184.108.40.2063 or later is required. Version 220.127.116.113 is available on http://www.labelwriter.com/software/dls/mac/DLS8Setup.18.104.22.1683.dmg
The complete sample is available on http://www.labelwriter.com/software/dls/sdk/samples/js/PrintLabel/PrintLabel.html
The code in the sample is in http://www.labelwriter.com/software/dls/sdk/samples/js/PrintLabel/PrintLabel.js
The sample is minimalistic. It just contains a text area element to specify a text to be printed on a label and a button that triggers printing.
The first thing should be done for any web project that uses the Framework is to include the library’s code, so it is available for scripts on the page. It is done like this:
This will include the latest version of the library. The only other hosted version for now is http://labelwriter.com/software/dls/sdk/js/DYMO.Label.Framework.1.0.beta.js
In the future other versions will be available as well. It is OK to host the file on your own web-server.
Print a Label
All printing code is in the printButton.onclick event handler assigned in PrintLabel.js. The print task contains three major steps: specifying label layout to print, setting data to print, selecting printer to print on, and actual printing.
Specify Label Layout to Print
Before a label can be printed we should specify what is the label, what objects it contains, what are their positions, etc. It is done by “opening” a label. The easiest way is to put the xml string describing the label right into openLabelXml() function. The easiest way to obtain the xml is to design the label using DYMO Label software, saving it into a file, then pasting file content into the js code.
var labelXml = '
<DieCutLabel Version="8.0" Units="twips">
<ForeColor Alpha="255" Red="0" Green="0" Blue="0" />
<BackColor Alpha="0" Red="255" Green="255" Blue="255" />
<Bounds X="332" Y="150" Width="4455" Height="1260" />
var label = dymo.label.framework.openLabelXml(labelXml);
In a real web application you would probably load the label definition xml from the server using some AJAX library instead of specifying it directly in a js file.
Setting Data to Print
The next step is to specify data to print on the label. This is easy:
The code sets the content for the object named “Text” to whatever is typed in the text area field on the page. Note: the library supports setting formatted/styled text as well. This ability will be reviewed in a different blog post.
Selecting the Printer to Print on
The printer should be selected from a list of installed printers. For this sample we choose the first LabelWriter printer:
var printers = dymo.label.framework.getPrinters();
if (printers.length == 0)
throw "No DYMO printers are installed. Install DYMO printers.";
var printerName = "";
for (var i = 0; i < printers.length; ++i)
var printer = printers[i];
if (printer.printerType == "LabelWriterPrinter")
printerName = printer.name;
If the printer name is known the printing is simple:
As you can see, label printing is not hard if DYMO Label Framework is being used. The Framework has a lot of other useful features, like multiple label printing, specifying image data for a label, specifying text styles, etc. These features will be reviewed in later posts.