user1794918
user1794918

Reputation: 1149

Dymo Framework Barcode Printing

On the onset let me say these are all the sites and places that I have been trying to figure out this issue of printing out a barcode on the label for the Dymo 450 LabelWriter.

http://developers.dymo.com/2010/06/02/dymo-label-framework-javascript-library-samples-print-a-label/ DYMO label JavaScript printing framework http://developers.dymo.com/2010/03/24/understanding-label-file-formats-in-dymo-label-v-8-label-objects/ Printing in Java to Label Printer

The dymo site is a large mess to me. I can't get a straight answer to anything I am looking for. I have tried to piece together code from their label site and it works. I want to add barcode to the label.

Here is what I have tried:

PrintLabel.js

    (function()
    {
        // called when the document completly loaded
        function onload()
        {
            var textTextArea = document.getElementById('textTextArea');
            var barCode = document.getElementById('barCode');
            var printButton = document.getElementById('printButton');

            // prints the label
            printButton.onclick = function()
            {
                try
                {
                    // open label
                    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/>\
            <ObjectInfo>\
                <TextObject>\
                    <Name>Text</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/>\
                </TextObject>\
                <Bounds X="332" Y="150" Width="4455" Height="160" />\
            </ObjectInfo>\
         <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="224" Y="150" Width="150" Height="120" />\
         </ObjectInfo>\ 
        </DieCutLabel>';
                    var label = dymo.label.framework.openLabelXml(labelXml);

                    // set label text
                    label.setObjectText("Text", textTextArea.value);
                    label.setObjectText("BARCODE", '721');

                    // 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);
                }
                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;

    } ());

Here is the HTML:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Print a Label</title> 
    <script src = "http://labelwriter.com/software/dls/sdk/js/DYMO.Label.Framework.latest.js" type="text/javascript" charset="UTF-8"> </script>
    <script src = "PrintLabel.js" type="text/javascript" charset="UTF-8"> </script>
    </head>

    <body>
    <h2>Lab Label</h2> 

        <div id="textDiv">
           <label for="textTextArea">Label :</label><br/> 
           <textarea name="textTextArea" id="textTextArea"  rows='5' cols='20'>
    <?php echo $name ."\n"; ?>
    <?php echo  date("Y-m-d") . "&#160;&#160;&#160;&#160;&#160;&#160;" .$oid."\n"; ?>


            </textarea>

            <input type="text" id="barCode" value="786">
        </div>

            <div id="printDiv">
                <button id="printButton">Print</button>
            </div>

    </body> 

    </html>

What I added from http://developers.dymo.com/2010/03/24/understanding-label-file-formats-in-dymo-label-v-8-label-objects/

site was the Barcode object. I thought I could drop it in and in would just work. But i have noticed that the TextObject code doesn't seem to do much either.

Any suggestions would be greatly appreciated.

Upvotes: 3

Views: 4048

Answers (1)

user1794918
user1794918

Reputation: 1149

Here is the final code that works now for the Print.js file.

    (function()
    {
        // called when the document completly loaded
        function onload()
        {
            var textTextArea = document.getElementById('textTextArea');
            var barCode = document.getElementById('barCode');       
            var printButton = document.getElementById('printButton');

            // prints the label
            printButton.onclick = function()
            {
                try
                {
                    // open label
                    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/>\
            <ObjectInfo>\
                <TextObject>\
                    <Name>Text</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/>\
                </TextObject>\
                <Bounds X="332" Y="150" Width="4455" Height="1260" />\
            </ObjectInfo>\
            <ObjectInfo>\
             <BarcodeObject>\
                 <Name>Barcode</Name>\
                 <ForeColor Alpha="255" Red="0" Green="0" Blue="0" />\
                 <BackColor Alpha="0" Red="255" Green="255" Blue="255" />\
                 <LinkedObjectName>BarcodeText</LinkedObjectName>\
                 <Rotation>Rotation0</Rotation>\
                 <IsMirrored>False</IsMirrored>\
                 <IsVariable>True</IsVariable>\
                 <Text>barCode</Text>\
                 <Type>Code128Auto</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="324" Y="950" Width="3150" Height="520" />\
         </ObjectInfo>\
        </DieCutLabel>';
                    var label = dymo.label.framework.openLabelXml(labelXml);

                    // set label text
                    label.setObjectText("Text", textTextArea.value);
                    label.setObjectText('Barcode', barCode.value);                
                    // 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);
                }
                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;

    } ());

Upvotes: 2

Related Questions