Nov 172011
 

Here is one more sample demonstrates capabilities of DYMO Label JavaScript library. The correspondent JavaScript file is here.

Getting Printers

First, the sample shows how to retrieve a list of available DYMO printers. For each printer it shows all the available properties. To get the printer list use dymo.label.framework.getPrinters function. The function returns an array contains information regarding each printer. The sample calls getPrinters and then put all the information onto a table, see createPrintersTable() for details.

Note: There are helpful function to filter the result list to contain only LabelWriter or Tape printers; use dymo.label.framework.getLabelWriterPrinters or dymo.label.framework.getTapePrinters accordingly. This might be useful if your application is designed to print on die-cut labels or D1 tapes only.

Print Multiple Labels

Next, the sample shows how to print multiple labels at once, in one print job. The sample leverages the library’s LabelSet functionality do archive that. For each printer the sample creates one label set record represent data to be printed on one label. also the sample demonstrates how to apply different text styles to the print data. It uses a feature called text markup, the ability to apply formatting attributes/tags very similar to HTML ones. 

// create label set to print printers' data
var labelSetBuilder = new dymo.label.framework.LabelSetBuilder();
for (var i = 0; i < printers.length; i++)
{
    var printer = printers[i];

    // process each printer info as a separate label
    var record = labelSetBuilder.addRecord();

    // compose text data
    // use framework's text markup feature to set text formatting
    // because text markup is xml you can use any xml tools to compose it
    // here we will use simple text manipulations to avoid cross-browser compatibility.
    var info = "<font family='Courier New' size='14'>"; // default font
    info = info + "Printer: <b>" + printer.name + "n</b>"; 
    info = info + "PrinterType: " + printer.printerType;
    info = info + "n<font size='10'>is local: " + printer.isLocal;
    info = info + "nis online: " + printer.isConnected + "</font>";

    if (typeof printer.isTwinTurbo != "undefined")
    {
        if (printer.isTwinTurbo)
            info = info + "<i><u><br/>The printer is TwinTurbo!!!</u></i>";
        else
            info = info + "<font size='6'><br/>Oops, the printer is NOT TwinTurbo</font>";
    }

    if (typeof printer.isAutoCutSupported != "undefined")
    {
        if (printer.isAutoCutSupported)
            info = info + "<i><u><br/>The printer supports auto-cut!!!</u></i>";
        else
            info = info + "<font size='6'><br/>The printer does not supports auto-cut</font>";
    }

    info = info + "</font>";

    // when printing put info into object with name "Text"
    record.setTextMarkup("Text", info);
}

See print() function for a complete sample.

Note: Here is another blog post regarding using text markup. And one more regarding printing multiple labels.

  22 Responses to “JavaScript Library Samples: Printers and Multiple Labels Printing”

  1. I would like to be able to use javascript to print a label on the right side slot of the TwinTurbo instead of the default left side. We will have a dropdown box to pick one or the other. What is the code to make it print on the right side?

    • you will need to construct print parameters object and pass the selected roll to it. Use dymo.label.framework.TwinTurboRoll enumeration to specify a valid value. Next, pass the print parameters as a second argument to label.print or dymo.label.framework.print. For example:

      var params = dymo.label.framework.createLabelWriterPrintParamsXml({twinTurboRoll: dymo.label.framework.TwinTurboRoll.Right});
      label.print(“DYMO LabelWriter 450 Twin Turbo”, params);

      • I have defined the print params exactly as you have here switching between left and right however it doesnt seem to matter it prints randomly to either side, I am using a continuous and price tag labels… so I need a way to define this for sure, is there a way we can confirm the params were accepted before print job is accepted maybe(for debug purposes not users, because I have wasted almost $30 dollars in price tags because it randomly decides to print a receipt on the price tag tape

        • Make sure you are running the latest DLS 8.5.1. Then try the role switching from DLS. Then try the role switching with the “\DYMO Label v.8 SDK\DYMO Label Framework\Samples\dotNET\C# Sample” sample app.

          void PrintWithLabelWriterPrintParams()
          {
          // open label layout
          ILabel label = Label.Open(“TextLabel.label”);

          // create printing parameters
          LabelWriterPrintParams printParams = new LabelWriterPrintParams();
          printParams.PrintQuality = LabelWriterPrintQuality.BarcodeAndGraphics;

          // print on left roll
          label.SetObjectText(“TEXT”, “Left”);
          printParams.RollSelection = RollSelection.Left;
          label.Print(“DYMO LabelWriter Twin Turbo”, printParams);

          // print on right roll
          label.SetObjectText(“TEXT”, “Right”);
          printParams.RollSelection = RollSelection.Right;
          label.Print(“DYMO LabelWriter Twin Turbo”, printParams);
          }

          • sorry for not specifying im using javascript

          • I have tried to defined using the createLabelWriterPrintParams and while the params are set it doesnt seem to respect it but rather prints to the last roll I used through the dymo software or if roll is empty it defaults to other side. I have confirmed that print2 and print have no difference and dymo.label.framework.print() and dymo.label.framework.print2() does not work. I have even gone as far as to uninstall dymo all together restart the computer and install 8.5.2 which the same problems persist

  2. I have read and re-read you site. I may be a bit new to javascript, but all I can seem to do to this point is print a basic label on the left and also on the right of my Twin Turbo

    What I really need to be able to do is
    1. Load a label layout file (DymoLargeRight.label) from java script
    2. set 3 field values (Address, ReturnAddress and Barcode) those are the Reference Names of each object
    3. Print to the Right Roll of the Twin Turbo

    I already have code working that tests for the printer and warns if not there so I don’t need that code.

  3. I need some help on printing multiple labels using the framework and jscript. I’ve managed to get the labels to print but none of them print with the USPS barcode. I used your multi-label example as my base but it doesn’t print mailing labels so it doesn’t deal with the barcode. The other mail label examples I can find only deal with individual labels instead of using the labelSetBuilder functionality. The original label xml has the barcode in it and I’m sure that I have just missed missed a line of code somewhere that tells it to add it but I can’t find it in the SDK.

    Here’s the label xml

    Landscape
    Address
    30252 Address

    Address

    Rotation0
    False
    True
    Left
    Middle
    ShrinkToFit
    True
    False

    DYMO
    828 San Pablo Ave Ste 101
    Albany, CA 94706-1678

    False
    AboveAddress

    Here’s the two functions I’m using

    function create_label (labelSetBuilder,labelvalues)
    {
    var record = labelSetBuilder.addRecord();
    var info = labelvalues[0]+”n”;
    info = info + labelvalues[1]+”n”;
    if (labelvalues[2]!= null)
    {
    info = info + labelvalues[2] + “n”;
    }
    if (labelvalues[3]!= null)
    {
    info = info + labelvalues[3] + “n”;
    }
    info = info + labelvalues[4]+ “, “;
    info = info + labelvalues[5]+ ” “;
    if (labelvalues[6]!= null)
    {
    info = info + labelvalues[6]+ ” “;
    }
    if (labelvalues[7]!= null)
    {
    info = info + “n”+labelvalues[7];
    }

    record.setText(“Address”, info);

    return (labelSetBuilder);
    }

    function print_label (labelSetBuilder, label, printerName)
    {
    //setlabel(labelSetBuilder);
    var params = dymo.label.framework.createLabelWriterPrintParamsXml({twinTurboRoll: dymo.label.framework.TwinTurboRoll.Auto});

    try
    {
    dymo.label.framework.printLabel(printerName, params, label, labelSetBuilder);
    }
    catch(e)
    {
    alert(e.message || e);
    }
    }

    The base code calls the first function and then immediately calls the second. As I said, I’m sure that I just missed something in the SDK but I can’t find it.

      • pi I just did… no help. I can get the labels to print using a method very similar to the one described. The issue is getting the USPS barcode to appear. The base label that I’m using is the DYMO “Address Barcode Top.label” which has the Barcode address instruction in the label xml (sorry the wordpress ate it above). I’ve also tried adding label.setAddressBarcodePosition(0,dymo.label.framework.AddressBarcodePosition.AboveAddress); after I define label as label = dymo.label.framework.openLabelXml(labelXml); where labelXml is the hardcoded Address Barcode Top.label. I also went into the UI to verify that the addresses I’m using for testing will pull a barcode thru the UI (they do). According to everything that I’ve read in the SDK, it should just work at this point. Any other suggestions?

  4. Hi there,

    I can’t seem to get the TwinTurbo labels to print on the side I specify. It jsut prints out the one side. Here’s a sample of my code: http://jsfiddle.net/bensinclair/bWrgx/2/

    Am I doing something wrong?

    Thanks

    Ben

  5. Great post. Informative too.
    Matt.

  6. Hi I looking for HTML and Js code for Multiple Labels Printing true IE browser. I have gone true all your SKD samples and cant get one to work… I am looking for a sample with 3 text boxes and a print all button can some one please help

  7. Hi,

    We are trying to do a label printing from ASP .NET application.

    The following is the code written in Javascript.

    function openLabelXml()
    {
    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.name == "DYMO LabelWriter 450 Turbo")
    {
    var labelXml = '

    Landscape
    Address
    30252 Address

    Text

    Rotation0
    False
    True
    Left
    Middle
    ShrinkToFit
    True
    False

    ‘;

    var label=dymo.label.framework.openLabelXml(labelXml);
    var labelSet = new dymo.label.framework.LabelSetBuilder();
    var textTextArea = $find(‘txtCenterName’);
    label.setObjectText(“Text”, textTextArea._value);
    label.print(“DYMO LabelWriter 450 Turbo”,null,label,labelSet);
    break;
    }
    }
    }

    However, it gives the below error.

    JavaScript runtime error: Unable to load label template

    Please let me know on how to resolve this issue.

    • Hi Naveena,

      Looking at the submitted code, the data that you are assigning to the variable labelXml is incorrect. The best way to do this is to create the desired label using the DLS software and load it via a file using the SDK. If you want to include the xml in your javascript, you will need to make sure that it is escaped properly.

      • Hi Dymodev,

        Thank you…
        I missed to add these code

        var record = labelSet.addRecord();
        record.setText(“Text”, textTextArea);
        label.print(“DYMO LabelWriter 450 Turbo”, ”, labelSet);

        Now it works..

  8. Hello,

    I love your SDK, it helped a lot on our app to print barcodes.
    I run up to an issue when using getPrinters() function.

    It returns the printer(s), in my case the DYMO 450, but it’s “isConnected” property is always “true”, even if it’s unplugged from the USB port.
    I use a mac, and on the printers and scanners it shows as offline.

    How can I fix the problem, so the barcode doesn’t go to print if the printer is not available?

    Thanks for your reply in advance.

    • What version of the SDK are you using? Have you tried a “clean” install first? Are you getting any error messages that you could provide me? Thanks.

 Leave a Reply

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=""> <s> <strike> <strong>

(required)

(required)