DYMO label JavaScript printing framework

Dean.DePue picture Dean.DePue · Jul 29, 2015 · Viewed 8.4k times · Source

My project involves printing patient labels on a Dymo 400 Turbo. I have installed the latest framework, DYMO.Label.Framework.latest.js, and am trying to use one approach I have found on the web to print the label. My problem is that the XML was designed for an address label and not a longer patient label. When I send to the printer it advances past the next label, wasting one. Plus I want to print the ID not the address or zip code in the bar code. Anyone have any ideas?

This is my XML:

 '<?xml version="1.0" encoding="utf-8"?>\
                    <DieCutLabel Version="8.0" Units="twips">\
                        <PaperOrientation>Landscape</PaperOrientation>\
                        <Id>Address</Id>\
                        <PaperName>30252 Address</PaperName>\
                        <DrawCommands>\
                            <RoundRectangle X="0" Y="0" Width="1581" Height="5040" Rx="270" Ry="270" />\
                        </DrawCommands>\
                        <ObjectInfo>\
                            <AddressObject>\
                                <Name>Address</Name>\
                                <ForeColor Alpha="255" Red="0" Green="0" Blue="0" />\
                                <BackColor Alpha="0" Red="255" Green="255" Blue="255" />\
                                <LinkedObjectName></LinkedObjectName>\
                                <Rotation>Rotation0</Rotation>\
                                <IsMirrored>False</IsMirrored>\
                                <IsVariable>True</IsVariable>\
                                <HorizontalAlignment>Left</HorizontalAlignment>\
                                <VerticalAlignment>Middle</VerticalAlignment>\
                                <TextFitMode>ShrinkToFit</TextFitMode>\
                                <UseFullFontHeight>True</UseFullFontHeight>\
                                <Verticalized>False</Verticalized>\
                                <StyledText>\
                                    <Element>\
                                        <Attributes>\
                                            <Font Family="Arial" Size="8" Bold="False" Italic="False" Underline="False" Strikeout="False" />\
                                            <ForeColor Alpha="255" Red="0" Green="0" Blue="0" />\
                                        </Attributes>\
                                    </Element>\
                                </StyledText>\
                                <LineFonts>\
                                    <Font Family="Arial" Size="8" Bold="False" Italic="False" Underline="False" Strikeout="False" />\
                                    <Font Family="Arial" Size="8" Bold="False" Italic="False" Underline="False" Strikeout="False" />\
                                    <Font Family="Arial" Size="8" Bold="False" Italic="False" Underline="False" Strikeout="False" />\
                                </LineFonts>\
                            </AddressObject>\
                            <Bounds X="332" Y="150" Width="4455" Height="1260" />\
                        </ObjectInfo>\
                    </DieCutLabel>'

I load up the label with this:

 var label = dymo.label.framework.openLabelXml(labelXml);
    var labelToPrint = getLabelToPrint();
    if (!label) {
        $("#lblError").text("There is no information entered to print");
        $("#MessageDialog").dialog({ title: "No Information" });
        $("#MessageDialog").dialog("open");
        return;
    }
    if (label.getAddressObjectCount() > 0) {
        var add = label.getAddressText(0);
        label.setAddressText(0, labelToPrint);
    }
    // set data using LabelSet and text markup
    var labelSet = new dymo.label.framework.LabelSetBuilder();

    var textMarkup = '';
    var fontSize = 18; // sets font size of first line


    if (labelToPrint == '') {
        $("#lblError").text("There is no information entered to print");
        $("#MessageDialog").dialog({ title: "No Information" });
        $("#MessageDialog").dialog("open");
        return false;
    }
    else {
        var lines = labelToPrint.split('\n');
        var boldLinesCount = lines.length <= 3 ? 1 : 2;
        for (var x = 0; x < lines.length; x++) {
            textMarkup += lines[x] + '\n';
        }
        //textMarkup += lines[0] + '\n';
        //textMarkup += lines[1] + '\n';
        //textMarkup += lines[2];
        label.setAddressText(0, textMarkup);
        //label.setObjectText("Barcode", lines[0]);
        label.setObjectText("Address", textMarkup);
        var record = labelSet.addRecord();
        record.setTextMarkup('Text', textMarkup); // set label text 
    }

Answer

user285594 picture user285594 · Feb 18, 2016

Dymo LabelWriter 450. In 2016 the world is upside down with this printer and with there documentation. Its a hell and nightmare. Dymo? please document it well.

Step 1:


A) Get latest versions of Javascript library and there driver

enter image description here enter image description here

B) old versions are screwed, full waste of time. C) better place to get start with: http://developers.dymo.com/2016/01/05/dymo-label-software-version-8-5-3-for-patch-release-macwin/

Step 2: copy paste, and smile.


<html>
<head>

<script type="text/javascript" src="http://www.labelwriter.com/software/dls/sdk/js/DYMO.Label.Framework.2.0.2.js"></script>
<script type="text/javascript">
function startupCode() {
  var printers = dymo.label.framework.getPrinters();
  if (printers.length == 0)
    throw "No DYMO printers are installed. Install DYMO printers.";

  dymo.label.framework.getPrintersAsync().then(function(printers){
    // Successful result, printers variable has a list of all supported by the DYMO Label Framework
    console.log(printers);
  }).thenCatch(function(error){
    // Error
  });

   var labelXml = '<?xml version="1.0" encoding="utf-8"?>\
                    <DieCutLabel Version="8.0" Units="twips">\
                        <PaperOrientation>Landscape</PaperOrientation>\
                        <Id>Address</Id>\
                        <PaperName>30252 Address</PaperName>\
                        <DrawCommands>\
                            <RoundRectangle X="0" Y="0" Width="1581" Height="5040" Rx="270" Ry="270" />\
                        </DrawCommands>\
 <ObjectInfo>\
        <BarcodeObject>\
            <Name>BARCODE</Name>\
            <ForeColor Alpha="255" Red="0" Green="0" Blue="0" />\
            <BackColor Alpha="0" Red="255" Green="255" Blue="255" />\
            <LinkedObjectName></LinkedObjectName>\
            <Rotation>Rotation0</Rotation>\
            <IsMirrored>False</IsMirrored>\
            <IsVariable>True</IsVariable>\
            <Text></Text>\
            <Type>Code39</Type>\
            <Size>Medium</Size>\
            <TextPosition>Bottom</TextPosition>\
            <TextFont Family="Arial" Size="8" Bold="False" Italic="False" Underline="False" Strikeout="False" />\
            <CheckSumFont Family="Arial" Size="8" Bold="False" Italic="False" Underline="False" Strikeout="False" />\
            <TextEmbedding>None</TextEmbedding>\
            <ECLevel>0</ECLevel>\
            <HorizontalAlignment>Center</HorizontalAlignment>\
            <QuietZonesPadding Left="0" Top="0" Right="0" Bottom="0" />\
        </BarcodeObject>\
        <Bounds X="331" Y="178" Width="4260" Height="420" />\
    </ObjectInfo>\
</DieCutLabel>';    

  var label = dymo.label.framework.openLabelXml(labelXml);
  label.setObjectText("BARCODE", '000220200');
  label.print("DYMO LabelWriter 450"); // This is the NAME of the printer which i found 
}
function frameworkInitShim() {
  dymo.label.framework.trace = 1; //true
  dymo.label.framework.init(startupCode); 
}
window.onload = frameworkInitShim;
</script>

</head>
<body>


</body>
</html>

Step 3: Printed correctly and console output was correct for debugging.

enter image description here

enter image description here