In this post we will look at different ways for printing multiple labels from a web application.
Option #1
The first option is just to call the print() method several times. Each call to print() will produce a single label. Between calls you will call other library functions like setObjectText() to update the label’s content. The pseudo-code is like this:
var label = dymo.label.framework.openLabelXml("<?xml>..."); // label #1 label.setObjectText("Text", "Some text"); label.print("DYMO LabelWriter 450 Turbo"); // label #2 label.setObjectText("Text", "Some other text"); label.print("DYMO LabelWriter 450 Turbo"); // label #3 // ...
This option is straightforward but unfortunately is not very efficient. Each call to print() function creates a separate print job. This might be a problem if hundreds of labels are being printed. But more important it might be not fast enough. The reason is that due to the printer hardware design some LabelWriter models might need to reverse feed a label at the beginning of each print job. Thus printing each label in a separate print job might be up to 5-10 times slower that printing all labels in one print job.
The solution is to do printing in one print job, so each label is printed as a single job’s “page”. For this there is option #2.
Option #2 – Printing Using a LabelSet
A “labelset” contains data to be printed on labels. Conceptually it is very similar to a dataset/recordset or a database table. A labelset consists of a set of records. Each record represents data for a single label. A record consists of a set of “fields”. Each field name is a name of an object on the label. A field value is text to be printed for that object. A record can be seen as a dictionary/associative array. The dictionary’s keys are label object names. The dictionary’s values are text for the label object. The dictionary can have only one key, e.g. if there is only one object on the label. But also it can have multiple keys to specify data for different label objects. It is NOT necessary to specify data for each object on the label; if a record does not have an appropriate key the object text will remain as-is (so, the object is a kind of ‘static’ text).
To do multiple label printing two pieces of information need to be defined. One piece defines what to print and the other piece defines how to print. “How to print” means how/where to put data on the label. That is specified by the label file. “What to print” is the actual data. That is specified by a labelset.
One more way to look at multiple label printing from the point of view of the MVC (Model-View-Controller) design pattern. In this case a labelset is the Model, the data to be processed/printed. A label (file) is the View. It specifies a presentation or layout for the data to be printed. And the library is the Controller, it binds the label and the labelset in print() operation.
LabelSet API
The Labelset API is quite simple. To create a labelset call dymo.label.framework.LabelSetBuilder constructor, like
var labelSet = new dymo.label.framework.LabelSetBuilder();
To add a new record, call the addRecord() method of the LabelSetBuilder object,
var record = labelSet.addRecord();
To set record data, call the setText() method. The first parameter is an object/field name, the second – an object text/field value,
record.setText("Description", itemDescription); record.setText("ItemCode", itemCode);
To print a labelset, just pass it as a third argument to print() method (the first argument is a parameter name, and the second argument is printing parameters; you can use empty string to specify default printing parameters),
label.print("DYMO LabelWriter 450 Turbo", '', labelSet);
Samples
To demonstrate using LabelSet we will look at two samples. Both of them use Google Docs spreadsheet as a data source. They take a spreadsheet data using Google Data JSON API and convert to appropriate labelset. The spreadsheet itself is displayed on a web page as well, so it is more clear what data are printed. Although for these samples spreadsheets are read-only it is possible to make them “editable”, so “live” data will be printed.
Sample #1 – Addresses
A spreadsheet for this sample contains address data. Each part of the address – name, street, city, state, zip – is in it’s own column. So, each spreadsheet row contains a full address, and specifies data for one label. The sample page is here, the java script code is here.
Upon page load a request is made to get the spreadsheet’s data:
function loadSpreadSheetData() { removeOldJSONScriptNodes(); var script = document.createElement('script'); script.setAttribute('src', 'http://spreadsheets.google. com/feeds/list/tSaHQOgyWYZb6mUPGgrsOGg/1/public/values?alt=json-in-script&callback=window. _loadSpreadSheetDataCallback'); script.setAttribute('id', 'printScript'); script.setAttribute('type', 'text/javascript'); document.documentElement.firstChild.appendChild(script); };
This is done by dynamically creating a <script> element to avoid cross-domain security restrictions. Upon request completion a callback function is called; the callback gets passed the returned spreadsheet’s data in json format to a function that generates a labelset and saves it in labelSet variable.
function loadSpreadSheetDataCallback(json) { labelSet = createLabelSet(json); };
createLabelSet() function iterates through all spreadsheet rows, and for each row it creates one labelset record. Each record contain only one “field”, because the label we going to print contains only one address object named “Address”.
function createLabelSet(json) { var labelSet = new dymo.label.framework.LabelSetBuilder(); for (var i = 0; i < json.feed.entry.length; ++i) { var entry = json.feed.entry[i]; var name = entry.gsx$name.$t; var street = entry.gsx$streetaddress.$t; var city = entry.gsx$city.$t; var state = entry.gsx$state.$t; var zip = entry.gsx$zip.$t; var address = name + 'n' + street + 'n' + city + ', ' + state + ' ' + zip; var record = labelSet.addRecord(); record.setText("Address", address); } return labelSet; }
As you see, the function is pretty straightforward. The most complex part is to get the spreadsheet’s columns values (name, street, city, etc variables) and combine them into one address block (address variable).
A label file is fetched from the server on the page loading as well. The label is saved in the “label” variable. We used jQuery library to fetch the label xml, but any other AJAX toolkit library can be used as well.
function loadLabel() { // use jQuery API to load label $.get("Address.label", function(labelXml) { label = dymo.label.framework.openLabelXml(labelXml); }, "text"); }
The final step is printing itself. It is done from Print button’s onclick handler.
printButton.onclick = function() { try { if (!label) throw "Label is not loaded"; if (!labelSet) throw "Label data is not loaded"; label.print(printersSelect.value, '', labelSet); } catch (e) { alert(e.message || e); } };
For simplicity the sample throws an exception if the label or labelset is still being loaded. If everything is OK, the printing itself is as simple as calling the print() method. There should be three labels printed with the following content:



Sample #2 – Inventory List
The second sample is very similar to the first one. The only difference is the data itself. For this sample the data is an inventory list with two columns. The first column is a textual description of an inventory item. The second is the item’s “code”/”id”. Instead of combining different columns into one field (as in the first sample), these two column are used independently to provide data for two different objects on the label. The “ItemDescription” column provides data for the text object, while the “ItemCode” column provides data for the barcode object. So, each record in the labelset will have two “fields”, one for each object. This is done by calling setText() method twice.
function createLabelSet(json) { var labelSet = new dymo.label.framework.LabelSetBuilder(); for (var i = 0; i < json.feed.entry.length; ++i) { var entry = json.feed.entry[i]; var itemDescription = entry.gsx$itemdescription.$t; var itemCode = entry.gsx$itemcode.$t; var record = labelSet.addRecord(); record.setText("Description", itemDescription); record.setText("ItemCode", itemCode); } return labelSet; }
The full code is available here. Four labels should be printed:




Conclusion
We have looked at two different ways to print multiple labels. The second one that uses a “labelset” concept is a recommended way to print multiple labels. You could even use it to print a single label, in this case you will not have to change your code much if you need to print multiple labels in the future. The data for labels might come from different sources, .e.g. entered directly by user, read from a corporate database, or fetched from a third-party provider like Google Docs as in the blog’s samples.
In the next post we will look at various ways to format text data on a label, e.g. how to specify different font size, font style, etc on character-by-character basis.
One thing I found interesting and stumped me for a bit before I debugged through the framework code: when using a labelset if you do
var record = labelSet.addRecord();
record.setText(“NAME”,”Alex”);
record.setText(“PRICE”,5); // this causes a crash
There is an issue, it bugs out at line 1769 of the latest hosted version. Its where you use objValue.indexOf. Obviously the issue here was me being an idiot and setting the price field to a 5 and not “5”, but it is a mistake you might consider catching in the framework and converting to string so that doesn’t fail.
Alex
I should be clearer, it only errors when you actually go to print the thing and it converts the labelset to xml, also is there any place to help and post bug reports other than the developers blog? or is this fine?
PS: framework rocks btw, this is so much nicer than the old way
Is there a way to use LabelSets with an applescript and from a pc command line
LabelSet API is not available from AppleScript. On Windows, the LabelSets are supported as a part of DYMO Label Framework API. There is no sample yet, but the code would be like this:
see DymoLabelFramework.chm from SDK installer for the LabelSetBuilder class reference
Greetings is it possible to use the dymo labelwriter with silverlight?
yes, it is possible, and there are several ways to archive it:
I am using SDK 8.2.3 V1.0. I wish to programmatically set the number of copies.
I defined the params as:
var printParamsXml = ‘
2
‘;
I get the desired number of labels with:
var labels = document.getElementById(‘labels’)
I have been unable to “discover” how to set the value of “Copies” at run time.
Any ideas? suggestions?
Thanks,
Bill
use createLabelWriterPrintParamsXml() function
/** Creates an xml stream suatable to pass to printLabel() function as printParamsXml parameter
// Created printing parameters are for printing on LabelWriter printers
// Parameters:
// – params – an JavaScript object with following properties (not all properties have to be defined, if a property is not defined a default value will be used)
// params.copies – number of copies to print
// params.jobTitle – print job title/description
// params.flowDirection – prints label content as left-to-right or right-to-left use FlowDirection enum to specify values
// params.printQuality – printing quality, one of ‘Text’, ‘BarcodeAndGraphics’, or ‘Auto’
// params.twinTurboRoll – the roll to print on if the printer is TwinTurbo. One of ‘Left”, ‘Right’, or ‘Auto’
*/
dymo.label.framework.createLabelWriterPrintParamsXml = function(params)
Then pass params xml to printLabel function, like
dymo.label.framework.printLabel(printerName, printParamsXml, labelXml)
Does this do it?
var labels = document.getElementById(‘labels’);
printParamsXml = createLabelWriterPrintParamsXml(params.copies = labels.value);
label.print(printerName,printParamsXml);
no
var labels = document.getElementById(‘labels’);
printParamsXml = dymo.label.framework.createLabelWriterPrintParamsXml({copies: labels.value});
label.print(printerName,printParamsXml);
Apologies for being so late to the party.
We have a need to be able to specify the number of labels to be printed by the EU in the interface.
I came across the XML allows to set the number of copies. But is there and HTML option to set the number of copies to print?
Thank you for helping an old functional programmer :-)
anytime :)
I am curious if you have any documentation or samples that illustrate how to format the data on the label (e.g. bold, italics, etc…). You eluded to such features above but I have been unable to location any information on how to accomplish this.
My specific situation is that I am using the JavaScript library to print from a web application and utilize the LabelSet feature to print multiple copies if reqeusted. Therefore, I am using the labelset.addrecord.setText method to get the text on the label. I have seen in the JS docs that there is also a setTextMarkup method but I am unclear on how to utilize this method.
Please advise and I apologize if the information has been here and I just haven’t found it.
Hi Eric,
Yes, setTextMarkup() has to be used. Unfortunately there are no samples and the documentation is very limited.
Anyway, the markup string passed to the function should contain a xml string according to the schema. The allowed tags are simple html tags for text formatting, e.g. ‘<b>’ to make text bold, ‘<i>’ for italic, etc. To specify font name and size use ‘font’ tag with ‘family’ and ‘size’ attributes. E.g. using the following markup text:
"<font family=’Courier New’ size=’36’>6×7=<b>42</b></font>"
the output will look like

Thank you Vladimir…that was a helpful start.
I am having trouble using the “” element in the setTextMarkup function call. When I pass “Address Line 1” to the function, everything prints as expected. However when I simply add “” to the text (e.g. “Address Line 1” I get the following error message “‘documentElement’ is null or not an object.”
I am currently working with a label layout with an Address Object named “ADDRESS” and I would like to pass all 3 or 4 lines of an address to it to be displayed on the label. I am assuming that I would need to utilize the tag in order to tell the Address Object where to begin a new line. Is this correct?
Thanks again for your help.
could you provide the full sample (seems like WordPress ‘ate’ some formatting)? I assume you are trying to insert line lines? to do that use
‘<br/> tag. Make sure it is ‘<br/> not just ‘<br>, so the markup string is well formed xml
Sorry about that…yes, WordPress did “eat” some of my last post. I think I was able to discern your advice and have tried it as well (as you will see).
If I pass “Line 1” to setTextMarkup everything is fine. However, if I add a break tag “
()
” to the end I receive the error message ‘documentElement is null or not an object.” If it doesn’t come through, the characters between the double quotes should be “lessthan, br, forwardslash, greaterthan”If this is the right code, I should be able to send “line1,break,line2,break,line3” to the function and receive a label with three lines on it, correct?
Thanks again.
Eric
I did not quite understand your note about “()”. Here is a sample that should print two lines:
The output is like this:
Measurement 1:
passed
also, you can use ‘new line’ character ‘n’:
Hi…
How can I preview a labelset?
there is no direct support for that, but it is possible. Basically you will have to call label.setObjectText() for each object data in a record, and then call label.render() to get a preview of the label for the particular record. Do this for each record in a label set.
Some samples for calling render are available on http://labelwriter.com/software/dls/sdk/samples/js/VisitorManagement/VisitorManagement.html
Thanks for your comment… I got one solution for it. This code is inside the “updatePreview” function.
var valores=labelSet.getRecords(); //get all the records we add to build the labelSet.
for (cont=1; cont<=valores.length;cont++)
{
setAddress(valores[cont-1]["Address"]); //Get the Address of each record and set the Address of the current label with this information..
pngData = label.render(); //label is defined just like in the preview example.
labelImage = document.getElementById('DymolabelImage'+cont); //we have several html div's for this .
labelImage.src = "data:image/png;base64," + pngData;
}
:D
Great! thanks for posting this.
I am using Firefox 9.0.1 and the latest dymo framework. The call
labelSet = new dymo.label.framework.LabelSetBuilder();
takes a LONG time… around 45-90 seconds. I have tried to only take this hit the first time, and if the labelset is already created, just emptying it and adding records for subsequent calls. This is marginally faster. Anyone else having this problem? Is there some way I can speed it up?
Thanks
Kevin
Please forward your question to DYMO according to the SDK Troubleshooting Tips post which can be found here http://developers.dymo.com/2011/10/12/sdk-troubleshooting-tips/
how can you add font styling when you’re using a template? for example my template has 12 text box fields ie txtAddress. I’m dynamically populating the string values but I can’t determine how to set the font size and type?
var labelXml = template generated from DYMO
var label = dymo.label.framework.openLabelXml(labelXml);
label.setObjectText(“txtAddress”,obj[i].Address);
Usually you specify font, alignment, etc by creating a label using DLS, so you don’t have to do it in code. It is still possible, but you have to use so called Low-Level API, see the documentation section “Low-Level COM Interface”. We have C++ sample in “DYMO Label v.8 SDKDLS SDKSamplesLow Level COMVisual C++” folder.
I have tried this multiple times, copied your code as is locally, and continue to get “Label is not loaded” on the local machine.
When I try your page (http://labelwriter.com/software/dls/sdk/samples/js/GoogleSpreadSheet/GoogleSpreadSheet.html) it works just fine.
What am I missing? What is your code for the GoogleSpreadSheet.html
You can view the GoogleSpreadSheet.html by loading the page in your Internet Explorer, right mouse click and select “View Source”. The used JavaScript can be found here http://labelwriter.com/software/dls/sdk/samples/js/GoogleSpreadSheet/GoogleSpreadSheet.js.
I have done that. Can you provide the file? The GoogleSpreadSheet.js is the same one I have tried… I know there is something simple… with it saying “Label is not loaded” could it be the Address.label file? A bundle of your exact code and files would be extremely helpful! :)
The JavaScript is trying to load the Address.label. The “Label is not loaded” message gets displayed when there was a problem with the loading of the label. The Address.label ships with the DLS software which can be found here http://download.dymo.com/software/Win/DLS842Setup.exe
I hate to ask, can you provide the Address.label file…
Hi – is it possible to print multiple DIFFERENT labels, e.g. a scenario where if a group of people attend an event (say 5), I want 1 print job to contain the 5 labels, and then do 1 more label for the leader with some specific info on it. How can I do this in 1 job?
If it’s impossible to do 1 print job, then if I’m sharing 1 dymo device between several (2 or 3) devices where the registrations are happening, then how can 1 device (which has 1 or more print jobs to send) reserve the printer or block off the others until its jobs are done?
You have to add all information from both labels to your .label layout. Then just populate the appropriate data for printing.
The DYMO SDK doesn’t provide any functionality to block off print jobs. This is handled by the OS. Therefore you have to come up with your own solution.
blocking off print-jobs is not such an issue if I can ‘chain’ my labels into 1 xml stream, adn therefore 1 print job per computer. Am I able to do something like this (where I’d then get 3 lable printed out each with formats/designs not necessarily like the other – but always same label size of course)??
http://shamiso.net/sample.txt
I would like to print multiple labels at once, we’re pulling the data from database into a php array, I want to be able to print a barcode and text, how the js will be in this case, I used the 1st sample above but thery’re using json and spreadsheet and I can’t figurate it out, I tried to remove json but it just doesn’t print. Here’s my js code:
(function()
{
var label;
var labelSet;
// called when the document completly loaded
function onload()
{
var itemCode = document.getElementById(‘itemCode’);
var textTextArea = document.getElementById(‘textTextArea’);
var printButton = document.getElementById(‘printButton’);
// prints the label
printButton.onclick = function()
{
try
{
// open label
var labelXml = ‘
Portrait
Small30334
30334 2-1/4 in x 1-1/4 in
Text
Rotation0
False
True
Left
Middle
AlwaysFit
True
False
Small30334
‘;
var label = dymo.label.framework.openLabelXml(labelXml);
// set label text
var labelSet = new dymo.label.framework.LabelSetBuilder();
for (var i = 0; i < record; ++i)
{
var record = labelSet.addRecord();
record.setText("Description", textTextArea);
record.setText("ItemCode", itemCode);
}
return labelSet;
// select printer to print on
// for simplicity sake just use 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;
break;
}
}
if (printerName == "")
throw "No LabelWriter printers found. Install LabelWriter printer";
// finally print the label
label.print(printerName);
var records = labelSet.getRecords();
for (var i = 0; i < records.length; ++i)
{
label.setObjectText("Description", records[i]["Description"]);
label.setObjectText("ItemCode", records[i]["ItemCode"]);
var pngData = label.render();
var labelImage = document.getElementById('img' + (i + 1));
labelImage.src = "data:image/png;base64," + pngData;
}
}
catch(e)
{
alert(e.message || e);
}
}
};
// register onload event
if (window.addEventListener)
window.addEventListener("load", onload, false);
else if (window.attachEvent)
window.attachEvent("onload", onload);
else
window.onload = onload;
} ());
Please check the PrintersAndMultipleLabelsPrinting sample which comes with the DYMO SDK.
We have web application running on Windows Azure. We are trying to print client side using the Javascript library and sample.
However, on the server when we fetch the label we need to populate it with dynamic data. That population process opens the label using the framework.dll and Label.Open(). However, the server does NOT have DYMO 8 installed and we’d like not to have to install it since it is in a cloud environment and technically that machine could be trashed and rebuilt without much notice. Without it installed we get a COM exception.
Basically, we are just using the library to open the label, check for objects by name and populate the text of the existing object, then spit out the xml again.
One option we have is to just use .NET framework and XPath to set values, but it would be nicer to use your built in library.
Any way to accomplish this without having to install DYMO 8 or register COM components?
I ended up just doing everything client side via JS.
DYMO Label Software (DLS) is installing and registering the COM components which are required to run DYMO .NET framework applications.
Do you have any samples on how to connect this to mysql database using php? I have been trying to do this with json but am not having much luck.
is it possible to pull two simple elements from a page to populate label.setObjectText… or do you need to set record?
cant get it to work correctly…
I have xml with two objects – text and barcode
var label = dymo.label.framework.openLabelXml(labelXml);
var pageid = document.getElementById(‘ID’);
var pagebarcode = document.getElementById(‘BARCODE’);
label.setObjectText(“ID”, pageid);
label.setObjectText(“BARCODE”, pagebarcode);
label.print(“DYMO LabelWriter 310”);
i can get this to work by manually entering data into label.setObjectText, but the ID and BARCODE are dynamically generated so want to pull them off a page.
All i get currently are errors (c.split is not a function) (c is undefined)
Did you have much luck with the “c.split is not a function” error?
I’m getting it as well. It looks like the problem was introduced in 1.2.2. The .js file is so hard to debug as it has been minified.
Does this happen with Firefox? Is it working with Chrome?
I have had this issue occur as well and I discovered in my case it was happening because I was trying to set label xml values in my label printing script for xml elements that did not exist in the xml. For example, if I had a label defined as barcodeLabel and I called barcodelabel.setObjectText(‘Top Barcode’, barcodeObjectText); but there was no ‘Top Barcode’ element in my label file xml it would throw the c is undefined error. It helps to log the vlaues you are setting to the xml label object to catch the actual cause of the undefined error.
Hi,
This may not be the right place to post this but I am entirely lost. I want to be able to fill out a spreadsheet and print out directly from googlesheets/excel. Is this possible?
I am not sure where I am supposed to copy this code from, or how to access DYMO’s SDK as the download option from their website seems to be non-functional.
I am not a computer-wiz, just a simple genomics researcher, so if anyone could help me with a tech-light walkthough that would be AMAZING. Thank you!
Hi Turner,
What website is non-functional? Have you tried the following page?
http://www.dymo.com/en-US/online-support-sdk
Regards,
Jeff
Hi,
since some time, I always receive “Label data is not loaded”, when I try to print labels from my online package. I really dan’t understand why this happens suddenly.
Somebody any idea?
Hi Bart,
Can you give me a little more detail about your issue? I assume you are using the javascript SDK? What version of DLS do you have installed? What operating system are you running?
ron
Hi Ron,
I use windows 10.
The DLS version is 8.6.1.42858
This is the js file that gives the error:
//—————————————————————————-
//
// $Id: GoogleSpreadSheetBarcodeLabel.js 12287 2010-06-17 03:47:32Z vbuzuev $
//
// Project ——————————————————————-
//
// DYMO Label Framework
//
// Content ——————————————————————-
//
// DYMO Label Framework JavaScript Library Samples:
// Print mulltiple labels using Google Spreadsheet as a data source
//
//—————————————————————————-
//
// Copyright (c), 2010, Sanford, L.P. All Rights Reserved.
//
//—————————————————————————-
(function()
{
var label;
var labelSet;
function onload()
{
var printButton = document.getElementById(‘printButton’);
var printersSelect = document.getElementById(‘printersSelect’);
function createLabelSet(json)
{
var labelSet = new dymo.label.framework.LabelSetBuilder();
for (var i = 0; i < php_var.length; ++i)
{
var Vrijwilliger = php_var[i];
var record = labelSet.addRecord();
record.setText("Vrijwilligers", Vrijwilliger);
}
return labelSet;
}
function loadSpreadSheetDataCallback(json)
{
labelSet = createLabelSet(json);
};
window._loadSpreadSheetDataCallback = loadSpreadSheetDataCallback;
function loadSpreadSheetData()
{
removeOldJSONScriptNodes();
var script = document.createElement('script');
script.setAttribute('src', 'http://spreadsheets.google.com/feeds/list/0Ak2RtsSi0A2bdFdka0Y1VUtZZHQ0VlRGQXg5QzROb2c/1/public/values?alt=json-in-script&callback=window._loadSpreadSheetDataCallback');
script.setAttribute('id', 'printScript');
script.setAttribute('type', 'text/javascript');
document.documentElement.firstChild.appendChild(script);
};
function removeOldJSONScriptNodes()
{
var jsonScript = document.getElementById('printScript');
if (jsonScript)
jsonScript.parentNode.removeChild(jsonScript);
};
function loadLabel()
{
// use jQuery API to load label
$.get("../CSS/DYMO/LabelVrijwilligers.label", function(labelXml)
{
label = dymo.label.framework.openLabelXml(labelXml);
}, "text");
}
// loads all supported printers into a combo box
function loadPrinters()
{
var printers = dymo.label.framework.getLabelWriterPrinters();
if (printers.length == 0)
{
alert("No DYMO LabelWriter printers are installed. Install DYMO LabelWriter printers.");
return;
}
for (var i = 0; i < printers.length; ++i)
{
var printer = printers[i];
var printerName = printer.name;
var option = document.createElement('option');
option.value = printerName;
option.appendChild(document.createTextNode(printerName));
printersSelect.appendChild(option);
}
}
// prints the label
printButton.onclick = function()
{
try
{
if (!label)
throw "Label is not loaded";
if (!labelSet)
throw "Label data is not loaded";
label.print(printersSelect.value, '', labelSet);
// var records = labelSet.getRecords();
// for (var i = 0; i < records.length; ++i)
// {
// label.setObjectText("Description", records[i]["Description"]);
// label.setObjectText("ItemCode", records[i]["ItemCode"]);
// var pngData = label.render();
//
// var labelImage = document.getElementById('img' + (i + 1));
// labelImage.src = "data:image/png;base64," + pngData;
// }
}
catch (e)
{
alert(e.message || e);
}
};
loadLabel();
loadSpreadSheetData();
loadPrinters();
};
// register onload event
if (window.addEventListener)
window.addEventListener("load", onload, false);
else if (window.attachEvent)
window.attachEvent("onload", onload);
else
window.onload = onload;
} ());
What is the value of “labelset” when you fail to print?
Ron
It says Label data is not loaded
I cannot be sure, but it sounds like you are not sending a label to the printer. You need to make sure you have valid label content.
Ron
Even when I put data in it directly by the script, it keeps saying this
Can I send you the php files and script, so that you can verify if it should be ok?
Hi Bart,
Have you looked at our samples? The best one to start with is:
http://labelwriter.com/software/dls/sdk/samples/js/PrintMeThatLabel/pl.html
In this sample you can see the proper mechanism for printing a label.
Hope this helps,
Ron
You can do a simulation and see what happens with this link:
https://administratie.lourdeslimburg.be/Lijsten/BoekingenDYMOFunctieSelectie.php
Can you try printing a single label?
It seems like he doesn’t pass the function labelset suddenly
Even iof I do this, it doesn’t work :(
function createLabelSet(json)
{
var labelSet = new dymo.label.framework.LabelSetBuilder();
for (var i = 0; i < 4; ++i)
{
var Vrijwilliger = "test";
var record = labelSet.addRecord();
record.setText("Vrijwilligers", Vrijwilliger);
}
return labelSet;
}
I suppose there is no problem that the package is now https instead of http?
Hi, I am trying to print labels from google sheet using app script. So far i didn’t get relevant material. Can you provide a very simple example on that.
I create the framework library on a seprate project and import as library. Now in next step i don’t know how to print the label. The attached spreadsheet on the blog are not available also.
If you would please provide a very simple example with static values. I will make it dynamic later.
Your cooperation will be highly appreciated. Thank you so much in advance.
I am sorry, we don’t have any samples using Google sheets. Does Google sheets support COM or Javascript? We have SDKs for those technologies.
Ron
Hello, i am using your library for printing multiple labels in my web project and it works.
The problem is that it is really slow to complete the operation; i use the #Option2 with the LabelSet API and have seen the Firefox developer console and the POST to PrintLabel to localhost:41951 takes 15-20 seconds to complete and then it prints fastly.
Can you suggest me a solution to reduce this time?
It is really slow for every print.
Thanks in advance and greetings
Hi Cris,
This is an issue we have been working on this week. A fix is now available!
For more info and download location see:
http://developers.dymo.com/wp-admin/post.php?post=1387&action=edit
ron
I use the Labelset method to print multiple barcode labels. Now that I have Window’s 10 the text prints, but the barcode will no longer print when using the label set and Windows 10. Is there a solution for this?
This is my code:
Dim LabelSet As Dymo.Label.Framework.ILabelSetBuilder
Dim Record As Dymo.Label.Framework.ILabelRecordBuilder
LabelSet = New Dymo.Label.Framework.LabelSetBuilder
Do Until CP > Pcnt
‘PrintPckLabel()
Try
Record = LabelSet.AddRecord()
Record.AddText(“txtPocket”, txtSelectedPck.Text)
Record.AddText(“txtBarcode”, txtSelectedPck.Text)
If rad2DBC.Checked = True Then
Record.AddText(“txtPocketV”, txtSelectedPck.Text)
Record.AddText(“txtBarcode2”, txtSelectedPck.Text)
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
CP = CP + 1
txtSelectedPck.Text = CP
Loop
‘Print the labelset
Dim printParams As Dymo.Label.Framework.IPrintParams
Dim Label As Dymo.Label.Framework.ILabel
If rad2DBC.Checked = True Then
Label = Dymo.Label.Framework.Framework.Open(Application.StartupPath & “\Resources\RxVPocketLabel2013.label”)
Else
Label = Dymo.Label.Framework.Framework.Open(Application.StartupPath & “\Resources\RxVPocketLabel.label”)
End If
Dim printer As Dymo.Label.Framework.IPrinter
Dim labelWriterPrinter As Dymo.Label.Framework.ILabelWriterPrinter
printer = Dymo.Label.Framework.Framework.GetPrinters()(LabelWriterCmb.Text)
If (TypeOf printer Is Dymo.Label.Framework.ILabelWriterPrinter) Then
labelWriterPrinter = printer
printParams = New Dymo.Label.Framework.LabelWriterPrintParams
If (labelWriterPrinter.IsTwinTurbo) Then
printParams.RollSelection = [Enum].Parse(GetType(Dymo.Label.Framework.RollSelection), “Left”)
Label.Print(LabelWriterCmb.Text, printParams, LabelSet.Xml)
Else
Label.Print(LabelWriterCmb.Text, printParams, LabelSet.Xml)
End If
End If
I can print the barcode using the dymoaddin in Windows 10, but I can’t figure out how to use the DymoAddin to print a labelset. I have to use Option 1 which creates a new print job for every label and is very inefficient. It works, but would prefer using a labelset.
Dim PCnt As Integer = DataGridView1.RowCount
Dim CP As Integer = 1
If Not PCnt > 1 Then Exit Sub
‘Hold current pocket number
Dim HCPN As Integer = “1”
If txtSelectedPck.Text = “” Then
‘No pocket selected
Else
HCPN = Trim(txtSelectedPck.Text)
End If
txtSelectedPck.Text = CP
Do Until CP > Pcnt
Try
If rad2DBC.Checked = True Then
DymoAddIn1.OpenURL(Application.StartupPath & “\Resources\RxVPocketLabel2013.label”)
Else
DymoAddIn1.OpenURL(Application.StartupPath & “\Resources\RxVPocketLabel.label”)
End If
Try
DymoLabels.SetField(“txtPocket”, Trim(txtSelectedPck.Text))
DymoLabels.SetField(“txtBarcode”, Trim(txtSelectedPck.Text))
DymoAddIn1.Print2(1, False, 0)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Catch ex As Exception
MsgBox(ex.ToString)
End Try
CP = CP + 1
txtSelectedPck.Text = CP
Loop
txtSelectedPck.Text = HCPN
HCPN = vbNull
Hi Alan,
I would suggest you look at the “DLS SDK Manual” page 15. This manual was included in the download of the DYMO SDK.
The code sample found here will point you in the right direction.
Regards,
Ron
I have Dymo LabelWriter 450, and i use 11354 label.
Please help me! Anyone know, what is the correct DrawCommands and the correct Bounds ????
If you have demo code for this label, many thanks….
Hi Daniel,
It is easiest to start with a label designed in DLS. the label file will have all of the correct information on it. You can simply load this label file into your application and update the contents of your label objects before you print.
regards,
Ron
I have a page that dumps some sql data in to a textbox in json format. The text box is hidden so the user never sees it. When they click the Print button How can I get that data to print on all the labels in one shoot ?
Hi Mike,
You can find our javascript SDK documentation here:
http://labelwriter.com/software/dls/sdk/docs/DYMOLabelFrameworkJavaScriptHelp/index.html
Ron
Thank you Ron I have look thought that and I don’t see where I can load a json array in to the createLabelSet
In option 2
unction loadSpreadSheetData()
{
removeOldJSONScriptNodes();
var script = document.createElement('script');
script.setAttribute('src', 'http://spreadsheets.google.
com/feeds/list/tSaHQOgyWYZb6mUPGgrsOGg/1/public/values?alt=json-in-script&callback=window.
_loadSpreadSheetDataCallback');
script.setAttribute('id', 'printScript');
script.setAttribute('type', 'text/javascript');
document.documentElement.firstChild.appendChild(script);
};
It’s loading from the google sheet I am trying to load in a json arrya in this format
[{"Barcode ":"M125942-002","part ":"F06984-0027","DESCR":"BACC69CCC0027J\/BOEIN, REV R","MFG":"M125942-002","Cable_Length":"27.125 Inches","Test_A":"0.03","Test_B":"0.05"},{"Barcode ":"M125942-003","part ":"F06984-0027","DESCR":"BACC69CCC0027J\/BOEIN, REV R","MFG":"M125942-003","Cable_Length":"27.125 Inches","Test_A":"0.06","Test_B":"0.04"}]
Hi Mike,
We don’t support exactly what you are asking for, you will need to parse the JSON.
Ron
ok what am I missing ?
//----------------------------------------------------------------------------
//
// $Id: GoogleSpreadSheetBarcodeLabel.js 38773 2015-09-17 11:45:41Z nmikalko $
//
// Project -------------------------------------------------------------------
//
// DYMO Label Framework
//
// Content -------------------------------------------------------------------
//
// DYMO Label Framework JavaScript Library Samples:
// Print mulltiple labels using Google Spreadsheet as a data source
//
//----------------------------------------------------------------------------
//
// Copyright (c), 2010, Sanford, L.P. All Rights Reserved.
//
//----------------------------------------------------------------------------
(function()
{
var label;
var labelSet;
function onload()
{
var printButton = document.getElementById('printButton');
var printersSelect = document.getElementById('printersSelect');
var mike2 = document.getElementById('mike');
function createLabelSet(json)
{
var obj = JSON.parse(mike2);
var labelSet = new dymo.label.framework.LabelSetBuilder();
for (var i = 0; i < json.feed.entry.length; ++i)
{
var entry = json.feed.entry[i];
var barcode = obj.Barcode;
var record = labelSet.addRecord();
record.setText("BARCODE", barcode);
}
return labelSet;
}
function loadSpreadSheetDataCallback(json)
{
labelSet = createLabelSet(json);
};
function removeOldJSONScriptNodes()
{
var jsonScript = document.getElementById('printScript');
if (jsonScript)
jsonScript.parentNode.removeChild(jsonScript);
};
function getBarcodeLabelXml()
{
var labelXml = '\
\
Landscape\
Address\
30252 Address\
\
\
\
\
\
ItemCode\
\
\
\
Rotation0\
False\
True\
1234\
Code128Auto\
Small\
Bottom\
\
\
None\
0\
Center\
\
\
\
\
\
\
Description\
\
\
\
Rotation0\
False\
True\
Center\
Top\
ShrinkToFit\
True\
False\
\
\
ItemDescription\
\
\
\
\
\
\
\
\
\
';
return labelXml;
}
function loadLabel()
{
// use jQuery API to load label
//$.get("Barcode.label", function(labelXml)
//{
label = dymo.label.framework.openLabelXml(getBarcodeLabelXml());
//}, "text");
}
// loads all supported printers into a combo box
function loadPrinters()
{
var printers = dymo.label.framework.getLabelWriterPrinters();
if (printers.length == 0)
{
alert("No DYMO LabelWriter printers are installed. Install DYMO LabelWriter printers.");
return;
}
for (var i = 0; i < printers.length; ++i)
{
var printer = printers[i];
var printerName = printer.name;
var option = document.createElement('option');
option.value = printerName;
option.appendChild(document.createTextNode(printerName));
printersSelect.appendChild(option);
}
}
// prints the label
printButton.onclick = function()
{
try
{
if (!label)
throw "Label is not loaded";
if (!labelSet)
throw "Label data is not loaded";
label.print(printersSelect.value, '', labelSet);
// var records = labelSet.getRecords();
// for (var i = 0; i < records.length; ++i)
// {
// label.setObjectText("Description", records[i]["Description"]);
// label.setObjectText("ItemCode", records[i]["ItemCode"]);
// var pngData = label.render();
//
// var labelImage = document.getElementById('img' + (i + 1));
// labelImage.src = "data:image/png;base64," + pngData;
// }
}
catch (e)
{
alert(e.message || e);
}
};
loadLabel();
loadPrinters();
};
function initTests()
{
if(dymo.label.framework.init)
{
//dymo.label.framework.trace = true;
dymo.label.framework.init(onload);
} else {
onload();
}
}
// register onload event
if (window.addEventListener)
window.addEventListener("load", initTests, false);
else if (window.attachEvent)
window.attachEvent("onload", initTests);
else
window.onload = initTests;
} ());
When I click Print I get “Label data not loaded “
Hi Mike,
Try printing the labels one at a time to help debug the issue.
Ron
ok so I changed
var mike2 = document.getElementById(‘mike’).value;
and changed
var obj = $.parseJSON(mike2);
function createLabelSet(json)
{
var labelSet = new dymo.label.framework.LabelSetBuilder();
var barcode = obj.Barcode;
var record = labelSet.addRecord();
record.setText(“ItemCode”, barcode);
record.setText(“Description”, barcode);
and did this
loadLabel();
loadSpreadSheetDataCallback();
loadPrinters();
to call it
Now I am getting “Unable to get property ‘toString’ of undefined or null reference”
return labelSet;
}
ok I can’t get this to work
how can I do this with my json data
[{"Barcode":"M125942-002","part":"F06984-0027"}]
If I can get it to work with just 2 fields I can add the other fields
I think this is the problem
function onload()
{
var mike = '[{"Barcode":"M125942-002","part":"F06984-0027"}]';
var obj = jQuery.parseJSON(mike);
}
function createLabelSet(json)
{
var labelSet = new dymo.label.framework.LabelSetBuilder();
for (var i = 0; i < JSON.parse(obj).length; ++i)
{
var entry = json.feed.entry[i];
var Barcode= entry.gsx$itemdescription.$t;
var Part= entry.gsx$itemcode.$t;
var record = labelSet.addRecord();
record.setText("Description", Barcode);
record.setText("ItemCode", Part);
}
return labelSet;
}
any help on just getting a small part working I can run with the
Wow I got it working
add his in the function onload()
var mike = '[{"Barcode":"M125942-002","part":"F06984-0027"}]';
var obj = jQuery.parseJSON(mike);
and this
function createLabelSet(json)
{
var labelSet = new dymo.label.framework.LabelSetBuilder();
for (var i in obj)
{
var itemDescription = obj[i].Barcode;
var itemCode = obj[i].part;
var record = labelSet.addRecord();
record.setText("Description", itemDescription);
record.setText("ItemCode", itemCode);
}
return labelSet;
}
And is worked so from here I can go crazy and add way more stuff.
I am trying to have 2 print buttons 1 will print all the data and button 2 will only print the data that is picked by the user.
Here is my code
Search
.text {color: #000; font-family:Arial, Helvetica, sans-serif }
.head {color: #000; font-family:Arial, Helvetica, sans-serif }
.input {display:none;}
.tftable {font-size:12px;color:#333333;width:100%;border-width: 1px;border-color: #729ea5;border-collapse: collapse;}
.tftable th {font-size:12px;background-color:#acc8cc;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;text-align:left;}
.tftable tr {background-color:#d4e3e5;}
.tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;}
.tftable tr:hover {background-color:#ffffff;}
<form action="" method="POST" >
Enter Work Order #:
Printer:
Print
Printer location (url)
Add
Clear
<?php
ini_set("display_errors",1);
error_reporting(E_ALL);
if(isset($_POST['submit']))
{
$UsrWorkOrder = $_POST['Work_Order'];
//db connect info
include 'conn.php';
//Where the query are stored
include 'Query.php';
$result_Vis = odbc_exec($conn_Vis,$sql_Vis); // Get Data From Result
while($row2 = odbc_fetch_array($result_Vis))
{
//Store the data in the new array
$result_cor1db01_2 = odbc_exec($conn_cor1db01_2,$sql_cor1db01_2); // Get Data From Result
$json = array();
echo "";
Echo "Work OrderPart NumberDescriptionMfg Lot NumberCable LengthTest Results ATest Results B";
$num_rows = odbc_num_rows($result_cor1db01_2);
while($row3 = odbc_fetch_array($result_cor1db01_2))
{
//This stores the data
$Serial_No = $row3["Serial No"];
$Barcode = $row3["Work Order No"]."-". $row3["Serial No"];
$part = $row2["PART_X"];
$DESCR = $row2["DESCR_X"];
$MFG = $row3["Work Order No"]."-". $row3["Serial No"];
$Cable_Length = $row3["ValueInches"];
IF(number_format($row3["Value1"],2)[0] < "1"){
$Test_A = substr(number_format($row3["Value1"],2), 1);
}Else{
$Test_A = number_format($row3["Value1"],2);
}
IF(number_format($row3["Value2"],2)[0] $Serial_No,
'Barcode' => $Barcode,
'part' => $part,
'DESCR' => $DESCR,
'MFG' => $MFG,
'Cable_Length' => $Cable_Length,
'Test_A' => $Test_A,
'Test_B' => $Test_B
);
// Echo "";
Echo "".$row3["Work Order No"]."-". $row3["Serial No"]."";
Echo "".$part."";
Echo "".$DESCR."";
Echo "" .$row3["Work Order No"]."-". $row3["Serial No"]."";
Echo "". $row3["ValueInches"]."";
IF(number_format($row3["Value1"],2)[0] < "1"){
Echo "".substr($row3["SS1"], -1)." " .substr(number_format($row3["Value1"],2), 1)."";
}Else{
Echo "".substr($row3["SS1"], -1)." " .number_format($row3["Value1"],2)."";
}
IF(number_format($row3["Value2"],2)[0] < "1"){
Echo "".substr($row3["SS2"], -1)." " .substr(number_format($row3["Value2"],2), 1)." ";
}Else{
Echo "".substr($row3["SS2"], -1)." " .number_format($row3["Value2"],2)."";
}
echo "Print Me";
//Echo "Test Results: ".substr($row3["SS1"], -1)." " .number_format($row3["Value1"],2)."";
//Echo "Test Results: ".substr($row3["SS2"], -1)." " .number_format($row3["Value2"],2)."";
}
//$printMe= json_encode($json);
//echo json_encode($json);
echo "".$num_rows ." Rows";
Echo "";
}
?>
$(function()
{
$('button.printme').on('click',function()
{
var json = $(this).data('json');
var mike = $('#mike').text();
var objMike = JSON.parse(mike);
//console.log(mike2);
var NewMike = objMike.filter(function(ss)
{
return ss.Serial_No == json;
});
console.log(NewMike);
var UpdateJson = JSON.stringify(NewMike)
$('#mike2').text(UpdateJson);
$('#printONEButton').click
});
});
so when a user enters a work order number and click search it querys a db and gets the info and put it’s in to a json array.
If the data it querys has more then 1 row it list all the data in to a table.
When the user clicks the Print Me button at the end of each row it updates the json with the new info that new info it put in the
The PrintMeThatLabel2.js load on page load is there a way NOT to have it load on page load and ONLY if user Click the BIG print button at the top to print all the data
OR
Click the print me button to print just the 1 row of data.
here is my PrintMeThatLabel2.js file
//----------------------------------------------------------------------------
//
// $Id: GoogleSpreadSheetBarcodeLabel.js 38773 2015-09-17 11:45:41Z nmikalko $
//
// Project -------------------------------------------------------------------
//
// DYMO Label Framework
//
// Content -------------------------------------------------------------------
//
// DYMO Label Framework JavaScript Library Samples:
// Print mulltiple labels using Google Spreadsheet as a data source
//
//----------------------------------------------------------------------------
//
// Copyright (c), 2010, Sanford, L.P. All Rights Reserved.
//
//----------------------------------------------------------------------------
(function()
{
var NodeType = {
ELEMENT: 1,
ATTRIBUTE: 2,
TEXT: 3,
CDATA_SECTION: 4,
ENTITY_REFERENCE: 5,
ENTITY: 6,
PROCESSING_INSTRUCTION: 7,
COMMENT: 8,
DOCUMENT: 9,
DOCUMENT_TYPE: 10,
DOCUMENT_FRAGMENT: 11,
NOTATION: 12
};
/**
* Removes all the child nodes on a DOM node.
* @param {Node} node Node to remove children from.
*/
var removeChildren = function(node) {
// Note: Iterations over live collections can be slow, this is the fastest
// we could find. The double parenthesis are used to prevent JsCompiler and
// strict warnings.
var child;
while ((child = node.firstChild)) {
node.removeChild(child);
}
};
/**
* Returns the owner document for a node.
* @param {Node|Window} node The node to get the document for.
* @return {!Document} The document owning the node.
*/
var getOwnerDocument = function(node) {
// TODO(user): Remove IE5 code.
// IE5 uses document instead of ownerDocument
return /** @type {!Document} */ (
node.nodeType == NodeType.DOCUMENT ? node :
node.ownerDocument || node.document);
};
/**
* Cross-browser function for setting the text content of an element.
* @param {Element} element The element to change the text content of.
* @param {string} text The string that should replace the current element
* content.
*/
var setTextContent = function(element, text) {
if ('textContent' in element) {
element.textContent = text;
} else if (element.firstChild &&
element.firstChild.nodeType == NodeType.TEXT) {
// If the first child is a text node we just change its data and remove the
// rest of the children.
while (element.lastChild != element.firstChild) {
element.removeChild(element.lastChild);
}
element.firstChild.data = text;
} else {
removeChildren(element);
var doc = getOwnerDocument(element);
element.appendChild(doc.createTextNode(text));
}
};
// app settings stored between sessions
var Settings = function()
{
this.currentPrinterName = "";
this.printerUris = [];
}
// loads settings
Settings.prototype.load = function()
{
var currentPrinterName = Cookie.get('currentPrinterName');
var printerUris = Cookie.get('printerUris');
if (currentPrinterName)
this.currentPrinterName = currentPrinterName;
if (printerUris)
this.printerUris = printerUris.split('|');
}
Settings.prototype.save = function()
{
Cookie.set('currentPrinterName', this.currentPrinterName, 24*365);
Cookie.set('printerUris', this.printerUris.join('|'), 24*365);
}
var label;
var labelSet;
function onload()
{
var printButton = document.getElementById('printButton');
var printersSelect = document.getElementById('printersSelect');
var printerSettingsButton = document.getElementById('printerSettingsButton');
var printerSettingsDiv = document.getElementById('printerSettingsDiv');
var printerUriTextBox = document.getElementById('printerUriTextBox');
var addPrinterUriButton = document.getElementById('addPrinterUriButton');
var clearPrinterUriButton = document.getElementById('clearPrinterUriButton');
var printersComboBox = document.getElementById('printersComboBox');
var jobStatusMessageSpan = document.getElementById('jobStatusMessageSpan');
var settings = new Settings();
// save settings to cookies
function saveSettings()
{
settings.currentPrinterName = printersComboBox.value;
settings.save();
}
// caches a list of printers
var printers = [];
// loads all supported printers into a combo box
function updatePrinters()
{
// clear first
removeChildren(printersComboBox);
printers = dymo.label.framework.getPrinters();
if (printers.length == 0)
{
alert("No DYMO printers are installed. Install DYMO printers.");
return;
}
for (var i = 0; i < printers.length; i++)
{
var printerName = printers[i].name;
var option = document.createElement('option');
option.value = printerName;
option.appendChild(document.createTextNode(printerName));
printersComboBox.appendChild(option);
if (printerName == settings.currentPrinterName)
printersComboBox.selectedIndex = i;
}
printerSettingsDiv.style.display= printers.length == 0 ? 'block' : 'none';
};
//This loads the data from the imput box. It's in Json format [{"Barcode":"M123346-002","part":"F06984-00437","DESCR":"BACC69CCC0043J\/BOEIN, REV R","MFG":"M123346-002","Cable_Length":"43.375 Inches","Test_A":"0.05","Test_B":"0.13"}]
//This is for testing the json format and if you need to test label printing.
//This is the Test data
//var mike = '[{"Serial_No":"001","Barcode":"M123346-002","part":"F06984-00437","DESCR":"BACC69CCC0043J\/BOEIN, REV R","MFG":"M123346-002","Cable_Length":"43.375 Inches","Test_A":".05","Test_B":".13"}]';
var mike = document.getElementById('mike').innerText;
//This is parse the json data.
var obj = jQuery.parseJSON(mike);
function loadcreateLabelSet(json)
{
labelSet = createLabelSet(json);
};
function createLabelSet(json)
{
var labelSet = new dymo.label.framework.LabelSetBuilder();
//This is looping thought the data in the josn so we can put a var to each obj.
for (var i in obj)
{
//This is getting the name Barcode from the json an storeing the next field after the ,.
var Barcode = obj[i].Barcode;
var part = obj[i].part;
var DESCR = obj[i].DESCR;
var MFG = obj[i].MFG;
var Cable_Length = obj[i].Cable_Length;
var Test_A = obj[i].Test_A;
var Test_B = obj[i].Test_B;
//This is addeding the the json data to each text field in the lable xml.
var record = labelSet.addRecord();
// so "BARCODE" is the place holder in the label xml and Barcode is the var from the json data.
record.setText("BARCODE", Barcode);
record.setText("PartNumber", part);
record.setText("Description", DESCR);
record.setText("MfgLotNumber", MFG);
record.setText("CableLength", Cable_Length);
record.setText("TestResultsA", Test_A);
record.setText("TestResultsB", Test_B);
}
return labelSet;
}
function getBarcodeLabelXml()
{
var labelXml = '\
\
Landscape\
LargeShipping\
false\
30256 Shipping\
\
\
\
\
\
TEXT\
\
\
\
Rotation0\
False\
False\
-1\
False\
Left\
Top\
ShrinkToFit\
True\
False\
\
\
Part Number:\
\
\
\
\
\
\
\
\
\
\
\
TEXT_1\
\
\
\
Rotation0\
False\
False\
-1\
False\
Left\
Top\
ShrinkToFit\
True\
False\
\
\
Description:\
\
\
\
\
\
\
\
\
\
\
\
TEXT_2\
\
\
\
Rotation0\
False\
False\
-1\
False\
Left\
Top\
ShrinkToFit\
True\
False\
\
\
Mfg Lot Number:\
\
\
\
\
\
\
\
\
\
\
\
TEXT_4\
\
\
\
Rotation0\
False\
False\
-1\
False\
Left\
Top\
ShrinkToFit\
True\
False\
\
\
Cable Length:\
\
\
\
\
\
\
\
\
\
\
\
TEXT_5\
\
\
\
Rotation0\
False\
False\
-1\
False\
Left\
Top\
ShrinkToFit\
True\
False\
\
\
Test Results:\
\
\
\
\
\
\
\
\
\
\
\
TEXT_6\
\
\
\
Rotation0\
False\
False\
-1\
False\
Left\
Top\
ShrinkToFit\
True\
False\
\
\
IL(db)-Aside:\
\
\
\
\
\
\
\
\
\
\
\
TEXT_7\
\
\
\
Rotation0\
False\
False\
-1\
False\
Left\
Top\
ShrinkToFit\
True\
False\
\
\
IL(db)-Bside:\
\
\
\
\
\
\
\
\
\
\
\
TEXT_3\
\
\
\
Rotation0\
False\
False\
-1\
False\
Center\
Top\
AlwaysFit\
True\
False\
\
\
Cage Code: 3ET44 Do Not remove from package until ready for use.\
\
\
\
\
\
\
\
\
\
\
\
BARCODE\
\
\
\
Rotation0\
False\
True\
-1\
False\
BARCODE\
Code128B\
Small\
Bottom\
\
\
None\
0\
Center\
\
\
\
\
\
\
PartNumber\
\
\
\
Rotation0\
False\
False\
-1\
False\
Left\
Top\
ShrinkToFit\
True\
False\
\
\
Part Number Test\
\
\
\
\
\
\
\
\
\
\
\
Description\
\
\
\
Rotation0\
False\
False\
-1\
False\
Left\
Top\
ShrinkToFit\
True\
False\
\
\
Description Test\
\
\
\
\
\
\
\
\
\
\
\
MfgLotNumber\
\
\
\
Rotation0\
False\
False\
-1\
False\
Left\
Top\
ShrinkToFit\
True\
False\
\
\
MfgLotNumber\
\
\
\
\
\
\
\
\
\
\
\
CableLength\
\
\
\
Rotation0\
False\
False\
-1\
False\
Left\
Top\
ShrinkToFit\
True\
False\
\
\
Cable Lengh\
\
\
\
\
\
\
\
\
\
\
\
TestResultsA\
\
\
\
Rotation0\
False\
False\
-1\
False\
Left\
Top\
ShrinkToFit\
True\
False\
\
\
Test A\
\
\
\
\
\
\
\
\
\
\
\
TestResultsB\
\
\
\
Rotation0\
False\
False\
-1\
False\
Left\
Top\
ShrinkToFit\
True\
False\
\
\
Test B\
\
\
\
\
\
\
\
\
\
\
\
TEXT_8\
\
\
\
Rotation0\
False\
False\
-1\
False\
Left\
Top\
AlwaysFit\
True\
False\
\
\
(When inspection is required, repack and reseal.)\
\
\
\
\
\
\
\
\
\
';
return labelXml;
}
function loadLabel()
{
label = dymo.label.framework.openLabelXml(getBarcodeLabelXml());
}
printerSettingsButton.onclick = function()
{
if (printerSettingsDiv.style.display == 'none')
printerSettingsDiv.style.display = 'block';
else
printerSettingsDiv.style.display = 'none';
}
// loads all supported printers into a combo box
function loadPrinters()
{
var printers = dymo.label.framework.getLabelWriterPrinters();
if (printers.length == 0)
{
alert("No DYMO LabelWriter printers are installed. Install DYMO LabelWriter printers.");
return;
}
for (var i = 0; i < printers.length; ++i)
{
var printer = printers[i];
var printerName = printer.name;
var option = document.createElement('option');
option.value = printerName;
option.appendChild(document.createTextNode(printerName));
printersSelect.appendChild(option);
}
}
// prints the label
printButton.onclick = function()
{
try
{
if (!label)
throw "Label is not loaded";
if (!labelSet)
throw "Label data is not loaded";
onload()
label.print(printersSelect.value, '', labelSet);
}
catch (e)
{
alert(e.message || e);
}
};
addPrinterUriButton.onclick = function()
{
try
{
var printerUri = printerUriTextBox.value;
if (!printerUri)
throw new Error("Specify printer Url");
dymo.label.framework.addPrinterUri(printerUri, '',
function()
{
settings.printerUris.push(printerUri);
saveSettings();
updatePrinters();
},
function()
{
alert('Unable to connect to "' + printerUri + '"');
}
);
}
catch(e)
{
alert(e.message || e);
}
}
clearPrinterUriButton.onclick = function()
{
dymo.label.framework.removeAllPrinterUri();
settings.printerUris = [];
saveSettings();
updatePrinters();
}
loadLabel();
loadcreateLabelSet();
loadPrinters();
};
function initTests()
{
if(dymo.label.framework.init)
{
//dymo.label.framework.trace = true;
dymo.label.framework.init(onload);
} else {
onload();
}
}
// register onload event
if (window.addEventListener)
window.addEventListener("load", initTests, false);
else if (window.attachEvent)
window.attachEvent("onload", initTests);
else
window.onload = initTests;
} ());
Hi Mike,
That is a lot of code…
Are you having trouble getting the SDK to work? I thought we had worked through those issues.
What issues are you having with this code?
Ron
the code is working on the main page I have 2 buttons 1 is the Big print button at the top. The users query a db it gets all the info builds a json then it drops it in the on the page. When you click the Big Print button the
PrintMeThatLabel2.js
Gets the info from the div builds the the Labelset and prints the labels. That works GREAT!
BUT what if the users just want to print 1 label
So the user enter the work order number and querys the db and pulls 10 rows and only want to print row 5.
I have added a Print Me button at the end of each row. When the user click the button I have some jquery that loads the json of all 10 row filters it by seral number and they are unique and reloads the with the row 5 json.
Then that is sent to the json then to the printer with $(‘#printButton’).click
PrintMeThatLabel2.js
loads the with the json info builds the labelset and prints.
BUT if the user want to then print ALL 10 labels they have to reload the page then click the big print button at the top.
is there a way in the PrintMeThatLabel2.js to store the json of all 10 rows and only build the labelset if the big print button is pressed.
and have PrintMeThatLabel2.js store the json if the user press the Print Me button and build that labelset.
this why the user doesn’t have to reload the main page to print all 10 after just printing 1 label out of the 10.
Does this make senses ?
P.S also the onload PrintMeThatLabel2.js is looking for data in the and will not load the printer unless there is a json to parse.
Can the json loading and parse and building labelset not be part og the onload and only be triggered by the onclick of the button ?
How do I use
dymo.label.framework.LabelWriterPrintQuality = text in the
PrintMeThatLabel.js
I tried
var speed = dymo.label.framework.LabelWriterPrintQuality(Text);
label.print(printersSelect.value, ”, labelSet, speed);
that didn’t work
anyone know how to enable
label = dymo.label.framework.LabelWriterPrintQuality(Text)
hello Ron,
Can you tell me how to set the dymo.label.framework.LabelWriterPrintQuality(Text)
I need the labels to print much faster as most of the time I print 40 at ones.
ok I did a console.log(dymo.label.framework.LabelWriterPrintQuality.Text);
that gives me Text
now how do I get it to print using LabelWriterPrintQuality.Text so it will print faster
Hi, I am running into an issue where sending multiple print jobs to the WebService will result in the first label printing properly, but then the second job will very slightly reverse the label spool before printing the next job, resulting in everything being offset to the right about 1/16″ or so, thereby cutting off some of the text on the right side of the label for all of the remaining jobs.
If I send a single job to print multiple copies of the same label, this does not happen. It’s only when sending multiple jobs.
For some more background, we have a receiving function in our Point of Sale system that allows a user to add multiple inventory items to a receiving invoice, then enter in the quantity of each item. Upon completion, it will print out price tag labels for each quantity of items. Each item sends its own print job since the data is different.
Is there a setting that will prevent this from happening? I am using the same XML template for all of the labels, just swapping out variables. I am not using the label framework, just sending API requests directly to the webservice from Javascript.
Any help would be appreciated.
Also, for what it’s worth, it does not seem to be having the offset issue on Windows, for what it’s worth. All of our production printing will be from Windows machines, so this is not as hot of an issue as I originally thought.