Jul 212010
 

A common question after reviewing the SDK sample applications installed with the SDK installer is “how can I set my own specific data onto the label in a format and layout of my choosing?” To do this you create a label using DLS 8. You can add label objects (Address, Text, Barcode, Image, etc.) onto the label and save it as a ‘template’ for your SDK code to use.

Scenario 1: Adding a TEXT object

First, run DLS 8 and design a label. Go to the Designer tab and edit the label. For this example, add a TEXT object by double-clicking on ‘Text’. You should now have a resizable rectangle on your label (see screen shot below).

Next, double-click on the rectangle to set the text object properties. Select the Advanced tab from the resulting dialog box. In the edit control titled ‘Reference name’ choose a unique name for this object (see screen shot below).

In this sample, I chose to name the object ‘TEXT1’. Your SDK code sets data on this object using this unique name. For instance,

Framework SDK (sample written in VB.NET)

Private Label As DYMO.Label.Framework.ILabel
Label = DYMO.Label.Framework.Framework.Open("c:Documents and SettingsAll 
UsersDocumentsDYMO LabelLabel FilesTestLabel.label")
Label.SetObjectText("TEXT1", "Testing, testing")
Label.Print("DYMO LabelWriter 450 Turbo")

DLS SDK API (sample written in C#)

myDymoAddin = new DymoAddIn();
myLabel = new DymoLabels();
if (myDymoAddin.Open(@"c:Documents and SettingsAll UsersDocumentsDYMO 
LabelLabel FilesTestLabel.label"))
{
    myLabel.SetField("TEXT1", "Testing, testing");
    myDymoAddin.StartPrintJob();
    myDymoAddin.Print(1, FALSE);
    myDymoAddin.EndPrintJob();
}

Output:

This sets the text, “Testing, testing”, onto the TEXT object which you named TEXT1 on your label. The exact same process would work for creating an ADDRESS object or a BARCODE object. You would simply refer to any other object you create by the name assigned in the Properties dialog (“TEXT1″ in our example) and change the corresponding line of code which sets the data onto this object. For example, if I had added a barcode object and assinged it the name ‘MYBARCODE’, my call to set the data for this barcode object might resemble the following:

myLabel.SetField("MYBARCODE", "97820315");

See Scenario 2 (below) for greater detail about adding a barcode object.

Scenario 2: Adding a BARCODE object

If instead, you would like to add a barcode object (either in addition to the TEXT object from Scenario 1 or all by itself), again, run DLS 8 to add this object to your label file template. Go to the Designer tab and edit the label. Add a BARCODE object by double-clicking on ‘Barcode’. You now have a resizable rectangle on your label (see screen shot below).

When you size the barcode object make sure its large enough to hold the barcode for your data! Next, double-click on the rectangle to set the barcode object properties. Select the Advanced tab from the resulting dialog box. In the edit control titled ‘Reference name’ choose a unique name for this object (see screen shot below).

In this sample, I chose to name the control ‘TEST_BARCODE’. Your SDK code sets data on this object using this unique name.  Next, click on the ‘General’ tab of the properties dialog box. You are now presented with options to change the barcode symbology (see screen shot below).

The code sample below will set the barcode data to ‘9876543’ for the particular label printed.

Framework SDK (sample written in VB.NET)

Private Label As DYMO.Label.Framework.ILabel
Label = DYMO.Label.Framework.Framework.Open("c:Documents and SettingsAll 
UsersDocumentsDYMO LabelLabel FilesTestLabel.label")
Label.SetObjectText("TEST_BARCODE", "9876543")
Label.Print("DYMO LabelWriter 450 Turbo")

DLS SDK API (sample written in C#)

myDymoAddin = new DymoAddIn();
myLabel = new DymoLabels();
if (myDymoAddin.Open(@"c:Documents and SettingsAll UsersDocumentsDYMO 
LabelLabel FilesTestLabel.label"))
{
    myLabel.SetField("TEST_BARCODE", "9876543");
    myDymoAddin.StartPrintJob();
    myDymoAddin.Print(1, FALSE);
    myDymoAddin.EndPrintJob();
}

Output:

Conclusion

The format of the label (objects found within the label and their locations) printed from your SDK application can easily be edited using DLS 8. The data passed to the objects is controlled through the SDK application itself. Using the SetField() functionality you can set your desired data into the formatted label template with total control.

  71 Responses to “How to set data on your label using the SDK”

  1. Hello!

    Regarding your Comment section on this about easily editing the format of a label: We want to use a .NET service to print on “Thermal Transfer Cryo-Tags” with a format of 1.50 x 0.50 inches (i.e. 38mm x 13mm).

    With the SDK/drivers used (v8.2; LabelWriter 400 Turbo) we have not found a possibility to create a .label file that can be used within our project to actually print a label. Any idea how to achieve this?

    Thanks!

    • The easiest way would be to use “large enough” label type to create a layout. For example, open DYMO Label software, select Shipping label type (it size is 2.125 x 4 inches), select portrait orientation, put any desired objects on desired positions (make sure they fit inside bounds of Cryo-Tag label), save the label. Now you can print on your Cryo-Tags labels using the saved label file.

  2. I can place data into a text object from my program (Your samples here made it quite easy!) but, when placing some descriptive text in a TEXT field, how can I get the data to wrap to multiple lines? Currently the data is either shrunk to microscopic size using “Shrink to Fit” or is simply truncated.

    Thanks,
    Steve G.

    • Unfortunately, Text object does not support word wrapping. So, the only choice is to manually separate the text to multiple lines.

      • Hmm… How would I find the size of the field and how it’s being rendered (font size/style/etc.) so I could determine where to put word breaks to wrap text?

        Thanks,

        Steve G.

        • This might be tricky. If your application uses a predefined label layout/file(s), then the simplest way is to open it in DYMO Label software and to estimate how many characters are fit in one line by just typing into the desire field(s) on the label. Knowing the average number of characters per line you will be able to split the input string into multiple lines. It is not necessary to know the exact layout for the text, because shrink-to-fit will do necessary shrinking if needed (it is even better to use ‘always-fit’ setting, so the text can be enlarged as well).
          If your application can print any label (a label somehow specified by a user) then you could use low-level API to get the object’s dimensions (using ILabelObject.Width and/or ILabelObject.Height) and object’s font information (using ITextObj.TextAttributes.Font_1 and ITextObj.TextAttributes.Font_2). Knowing these values you can calculate average chars per line using Win32 API or .NET text measuring functions.
          Both of these methods are not ideal, but there is no other way.

  3. Vladimir – Thanks for the information on splitting strings. How do I get access to the “low-level API”?

    Thanks,
    Steve G.

    • Low-level API is implemented by the same COM library as high-level API (Dymo.LabelAddIn object). Just use Dymo.LabelEngine object instead of Dymo.LabelAddIn Dymo.Labels objects. SDK contains a sample how to use “low-level” API in Low Level COM/Visual C++ folder.

  4. Which file in the “Dymo.v8.2.2″ SDK directory contains “DymoAddIn” and “DymoLabels”? I’m writing my program using LabVIEW2009 and .NET VIs. I have found “DymoAddIn” and “DymoLabels” constructors only in DYMO.DLS.SDK.dll file in the “DYMO Label Software” subdirectory. While the methods for Open, SetField, and Print return a TRUE, my Dymo400 doesn’t print. I can print using the DLS.exe of the same directory.

    Any help is greatly appreciated!

  5. How to change an image in a label loaded with javascript? SetObjectText will work for labels but the function label.setImageFile says “label.setImageFile is not a function”…

    • Solved.

      var label = dymo.label.framework.openLabelXml(labelXml);

      var myURI = dymo.label.framework.loadImageAsPngBase64(“http://www.myhost.com/myimage.jpg”);

      label.setObjectText(“myimagename”,myURI);

      • yes, loadImageAsPngBase64() will do it. A word of caution though: loadImageAsPngBase64() (as well as openLabelFile) is designed as a last resort – use it only if you cannot load an image/label file using standard browser’s capabilities, e.g. when you have to open a local file or load it from a different domain. So, the better way is to get base64 encoded data directly from the server, e.g. right some script to return base64 encoded data, then get it using Ajax, and finally pass the data to setObjectText(). So, the code might look like:


        var label = dymo.label.framework.openLabelXml(labelXml);
        $.get("getImage.php?image=myimage.png", function(imageBase64)
        {
        label.setObjectText("myimagename", imageBase64);
        }, "text");

        where getImage.php is a server-side script.

        Another way to is to load image data into Image object, render it into Canvas and finally get base64 encoded png data using Canvas.toDataURL() method.

        From the openLabelFile/loadImageAsPngBase64 documentation:

        There are some considerations should be taken into account before using this function.
        Use it only then there are no other way to load label data, that in most cases should be done using openLabelXml()
        – full file name/url should be specified. The function will not honor relative paths based on document.location.href
        – the fileName can be http:// or file:// urls. On Windows it can be a regular file name, like ‘c:usersdesktopaddress.label’
        – the content of the label will be loaded synchronously. So if the remote server is down there will be a timeout.
        – any local file can be accessed/tried to be accessed. The function is not limited by any browser restrictions.
        Though only a valid label file (according to label.xsd schema) can be loaded this still can be potential security concern.
        – the URL is not limited to same-site-origin browser policy – any url can be opened
        – the proxy settings are system default settings, not necessary browser settings.

  6. so is the new sample musing the beta sdk or the old ones ?
    what is the status of the new beta sdk?

    right now i have not found any sample that works with c# for any of the sdk versions i have downloaded yet.

    win 7 pro x64 and VS 2010

    I need to make a working sample using COM interop so that i can create a Silverlight out of browser app that prints labels.

    • We have samples for both APIs. For the Framework there is VS2010 solution located at DYMO Label FrameworkSamplesDYMOLabelFrameworkSamples.vs2010.sln For current API the sample is at Backward Compatible SDKSamplesHigh Level COMdotNET SamplesC# SampleCSharp Sample.csproj It is VS2005 project, so open it in VS2010 and reimport COM-references. If you have problems running theses samples – please describe the problem in details.

  7. We are trying to set an image as outlined above, with no luck. We’re attempting this as using base64 encoded data keeps giving us an ‘label template cannot be loaded’ error.

    Any insight into this would be helpful.

    • If you got ‘label template cannot be loaded’ error then something wrong with your label definition. Are you trying to load label from a file or url? If so, make sure you can open it inside DYMO Label software to make sure the label definition is OK. If you are loading the label from a hardcoded xml string, agian make sure the string itself is a valid xml and confirms to the schema

      • We re-encoded the graphic with an online encoder and used that in the XML file and that solved the issue. Thanks for your response.

  8. Is it possible to get an image that has been copied into clipboard into the image object of a label through .NET?

    • yes, though there is no separate method for that. The code will look like

      if (Clipboard.ContainsImage())
      {
      var clipImage = Clipboard.GetImage();
      var encoder = new PngBitmapEncoder();
      encoder.Frames.Add(BitmapFrame.Create(clipImage));

      var stream = new MemoryStream();
      encoder.Save(stream);
      stream.Position = 0;

      label.SetImagePngData("imageName", stream);
      }

  9. I’m passing base64 encoded images from PHP to JS using AJAX;

    I got 4 images on a label, but sometimes there should be less images, is there a workaround so I can ‘hide’ an image on the label?

    • I can think about three ways of doing it:

      • create a LabelSet and set data for correspondent image object to an empty string, this will clear the image content. Usually you will use LabelSet to print multiple labels at once, but it can be used to print just one label as well. To put image data into a LabelRecord use setBase64Image() method. For an complete example see http://developers.dymo.com/2010/06/17/dymo-label-framework-javascript-library-print-multiple-labels/
      • create and load a separate label file that will have only image object needed
      • create an 1×1 white pixel image on the server and use it as the image in case when no image is needed.
      • I didn’t want to wait for a solution so I tried some stuff;
        But setting the image object to an empty string causes a fault I guess, because Dymo can’t load the label then.
        So what I did was putting 4 images on the label, wich are white images, and replace that. And it works great at the moment!

        BTW, is there a chance to get the unminimized code? Because I’d like to show an alert when the user hasn’t installed the Dymo framework sdk. At this time an exception is thrown, but the user can’t see this…

  10. Do you have an example of how to pull data out of a MYSQL database, and the print it via a browser using PHP?

    • We don’t have the complete sample for that. But if you make the data available from the web-page in some sort of Ajax, then you could adapt this sample to use your data instead of Google Docs

  11. Hi,

    how can I change the text size of the TEXT object in C#?

    THX

    • Just for clarification – are you trying to change the object size or font size of the object’s text?

      if you want to change the object size there are two ways. First is to design a label using DYMO Label software, where you can adjust the object sizes visually. Second, using SDK API. For DYMO Label Framework a sample code will be:


      using DYMO.Label.Framework;
      var label = Label.Open(@"MyLabel.label") as IDieCutLabel;
      var oldBounds = label.ObjectBounds["MyTextObject"];
      var newBounds = new Rect(oldBounds.X, oldBounds.Y, oldBounds.Width, oldBounds.Height + 360); // 1/4" taller
      label.ObjectBounds["MyTextObject"] = newBounds;

      • Hi Vladimir,

        I am trying to change to font size, not the object size. The object size is fine in my designed label.

        THX

        • you can look for an example of ILabelSetBuilder interface in the DYMOLabelFramework.chm help file available in the SDK installation. Below is a sample function

          public void PrintWithLabelSet()
          {
              // open a label
              ILabel label = Label.Open("TextLabel.label");
          
              // create a builder object to populate label set 
              ILabelSetBuilder labelSetBuilder = new LabelSetBuilder();
          
              // label #1 - use font specified in the label file
              ILabelRecordBuilder record = labelSetBuilder.AddRecord();
              record.AddText("TEXT", "6x7=42");
          
              // label #2 - specify font programmatically using StyledTextBuilder
              record = labelSetBuilder.AddRecord();
              IStyledTextBuilder styledTextBuilder = new StyledTextBuilder();
              styledTextBuilder.Append(new StyledTextBlock("6x7=", new FontInfo("Courier New", 36, FontStyle.None), Colors.Black));
              styledTextBuilder.Append(new StyledTextBlock("42", new FontInfo("Courier New", 36, FontStyle.Bold), Colors.Black));
              record.AddStyledText("TEXT", styledTextBuilder.StyledText);
          
              // label #3 - specify font using a markup string
              record = labelSetBuilder.AddRecord();
              record.AddTextMarkup("TEXT", @"<font size='36'>6x7=<b>42</b></font>");
          
              label.Print("DYMO LabelWriter 450 Turbo", null, labelSetBuilder.Xml);
          }
          
      • Unfortunately it didn’t install the “DYMOLabelFramework.chm”. When I use your code Visual Studio tells me that I’m missing a reference, but which one?

  12. I’m using v.8 on Windows 7 64bit, if that changes anything.

  13. I’ve been asking for years… when are QR code support coming for web label printing? What is the easiest way to implement them now without waiting?

    • Experimental support for QRCode (as well as for PDF417) has been added in DYMO Label 8.3. You will have to edit a label file manually, because there is no UI support yet. Just create a label in DYMO Label, save it into a file, open a file in your preferred xml editor; locate barcode type element (XPath is like /DieCutLabel/ObjectInfo/BarcodeObject/Type); enter “QRCode” for the Type inner text. Now you can load this label using DYMO Label Framework JavaScript Library and set the barcode content as for any other barcode type, e.g. using label.setObjectText() or record.setText().

  14. Hello! I’m just starting to develop for Dymo functionality and I was trying to follow your example here but I can’t seem to get the file to open. Pertinent info:

    Using Visual Studio 2010
    Using VB.Net
    I think I have included the reference correctly but am unsure. I included the COM called “Dymo Label Software 7 SDK Compatible Library” (I was unable to include or even find the files for the version 8 sdk)
    I am simply trying to do a test print to see if I can get things working but as I said the boolean returned from trying to open the file returns false. Here is the code snippet below.

    Public Class frmMain

    Public DymoAddIn As Dymo.DymoAddIn
    Public DymoLabels As Dymo.DymoLabels
    Private Sub btnOpenPrint_Click(sender As System.Object, e As System.EventArgs) Handles btnOpenPrint.Click
    DymoAddIn = New Dymo.DymoAddIn
    DymoLabels = New Dymo.DymoLabels

    DymoAddIn.Open(“C:CPSLabelsCPSLabelsCPSLabelsCPS.label”)
    DymoLabels.SetField(“txt1″, “Test!”)

    DymoAddIn.Print2(1, False, 1)

    End Sub
    End Class

    I tried DymoAddin.Open2 and the prompt that came up would only look for .lwl files which I tried saving the label as but still a no go.

    Any help on how to get this simple test up and running would be greatly appreciated

    Cheers,
    Hoyty

  15. Is there a way to set the font to different values in the same “Text” object in a label? the reason i’m asking, is because i need to use the continuous label, but when i do this i can only use one text box (because that text box is automatically set to the width of the label and i can’t change the value; it is grayed out)

  16. The code below to load the image into the label is not showing the image.

    I there something wrong with the code?

    $.get(“getimage.php?filename=Photos/” + VstPic + “&filetype=png”, function (imageBase64) {
    myWindow.document.write(“Picture is encoded.”);
    label.setObjectText(“VstPic”, imageBase64);
    }, “text”);

    • Assumed that you called label.print or label.render to see the result of loading the image here are some suggestion for debugging:
      – make sure the object name is specified correctly. The name is case sensitive.
      – make sure you use the standard base64 encoding and NOT url-safe base64.
      – try to use DebugView as described in http://developers.dymo.com/2011/10/12/sdk-troubleshooting-tips/ to see the runtime error messages.
      – grab the value of imageBase64 variable and e-mail or post it here, so we can debug at our side.

      Thanks.

  17. by the way here the php code

  18. This is the PHP code

    $filename=$_GET['filename'];
    $filetype=$_GET['filetype'];

    if ($filename) {
    $imgbinary = fread(fopen($filename, “r”), filesize($filename));
    echo base64_encode($imgbinary);
    }

  19. I was wondering if anyone could help me.
    I have installed DLS8Setup.8.3.1.1332; still I didn’t connect the Printer.
    I wanted to design a sample label, when I try to open (DYMO Label v.8) its saying as “DYMO label requires a DYMO label printer be installed. Make sure your label printer is installed and connected”, is there any way to create label without connecting the dymo printer (But I have installed – DLS8Setup)

    thanks!
    Hasitha

  20. Hello
    We are converting our application from Access to VS2010 VB.Net

    I am trying to set up printing a label using Label Framework in VS 2010. My PC is Win 7 x64.
    I am using your sample code above
    ******
    Framework SDK (sample written in VB.NET)

    Private Label As DYMO.Label.Framework.ILabel
    Label = DYMO.Label.Framework.Framework.Open(“c:Documents and SettingsAll
    UsersDocumentsDYMO LabelLabel FilesTestLabel.label”)
    Label.SetObjectText(“TEST_BARCODE”, “9876543″)
    Label.Print(“DYMO LabelWriter 450 Turbo”)

    *********

    there is no Label = DYMO.Label.Framework.Framework.Open ……
    options when i follow your example. All I can get is Label = DYMO.Label.Framework.ILabel

    when i open a sample SKD project the code works there.
    I did add “DYMO.Label.Framework.dll assembly” to my project
    What am i missing ??

    Thanks
    Jim G

  21. Hi
    I am trying to use your VC++ command line, and although I can send a label, the address refuses to go on multiple lines, choosing to stay on one small line. This is going into an address field. Using your example: /objdata “Address=DYMO Customer 1234, Main Street, Any City, Any State, 94123″ I have tried many variants to this, none were succesfull. Do I need to have a different de limiter than comma?

    The object here is to create labels from a database (Ffenics) and send one or more labels to one of several Dymo450 with several /objdata fields on the label. The only thing I cant make work is the multi line address.

    • The delimitier is “%20″ e.g. /objdata “Address=DYMO Customer%201234 Main Street%20Any City, Any State, 94123″

      • Hi Thanks for reply.
        I did try the %20 so the line looked like this: /objdata “Address=DYMO Customer%20 1234 Main Street%20 Any City%20 Any State%20 94123″ but it still comes out on a single line.

        • It is working just fine here. Please make sure that your .label template file can be found and is valid. You might use DLS to create a new address .label template file.

          • Hi Thanks again for reply, but unfortunately it still remains the same. I created a new .label file, changed the batch file to point to the new file, but it still prints the whole of the address in one small line :(
            Batch File:
            printlabel /printer “DYMO LabelWriter 400 on emailp34″ /tray 0 /copies 1 /objdata “Address=DYMO Customer%20 1234 Main Street%20 Any City%20 Any State%20 94123″ “C:Documents and Settingspaul.cheesemanMy DocumentsDYMO LabelLabelsFfenics Address.label”

          • Incase it matters, the label prints out like this:
            DYMO Customer0 1234 Main Street0 Any City0 Any State0 94123

          • Does it work when you type the entire command on a Command Prompt instead of launching it from a batch file?

          • or try

            printlabel /printer “DYMO LabelWriter 400 on emailp34″ /tray 0 /copies 1 /objdata “Address=DYMO Customer%%20 1234 Main Street%%20 Any City%%20 Any State%%20 94123″ “C:Documents and Settingspaul.cheesemanMy DocumentsDYMO LabelLabelsFfenics Address.label”

            from a batch file.

          • Horaaa! That extra % sign did the trick, now to make the full multi field one do the same!

            Thanks for your help and solving the issue :)

            Paul

  22. I want to make a barcode label via JS, but i have now continious white labels.
    has someone a sample?

  23. How can I print a barcode and a text description using the Barcode and Text all in one label. I am trying to print a barcode with a number and a little description describing the product that the barcode is linked to. I can print the barcode and the text together, but it is only numbers that it prints and not anything else.

  24. how stretch to label the barcode with aspect ratio?

  25. I am trying to print a PDF417 barcode using a C# application. I am printing all good. But I want to sent an Enter key into the barcode text. For example:
    “one
    two
    three”

    This is because when the barcode is scanned by a scanner later, it registers three seperate entities seperated by the enter key.

    This is my code:
    barcodeToBePrinted = barcode1 + ‘\n’ + barcode2 + ‘\n’ + barcode3;
    var label = DYMO.Label.Framework.Label.Open(“BarcodeTemplate1.label”);
    label.SetObjectText(“BARCODE”, barcodeToBePrinted);
    label.Print(BarcodePrinterApplication.Properties.Settings.Default.Printer_Name);

    This results in the printer only printing ‘barcode1″ and not the rest. What is going on? What can I do to fix that?

    • The data should be encoded correctly into the barcoded. Barcode readers do vary. Do you see the same results with various barcode scanning applications?

  26. I made this project but it seems that the printer pulls the labels back and forth multiple times until is aligned I guess (im using the 2Up 0.5 x 1 inch). But when I use the SDK VB.net application it prints the labels (same label) much much faster and one after another one. My application (based on this post) prints one label and then throws one ot two labels and print the next one… any ideas in how to improve that?
    Thanks

  27. You’ll find some more information about printing barcodes here http://dymodevelopers.wordpress.com/tag/qr/

    Please also check your label template with DYMO Label Software (DLS).

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>