troubleshooting Question

Dymo JavaScript Printing Issue

Avatar of tsmith02
tsmith02 asked on
JavaScript
2 Comments1 Solution221 ViewsLast Modified:
Can someone tell me why the "Custom Label" portion of the following page will not print?  I would like it to take the value entered by the user into the box and pass it on to the printer for printing.  The XML dictates the layout of the label, and is in use in another script that functions perfectly.  I do not believe that is the issue, but I suspect it's a javascript problem.

Thanks!!

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"/>
<link rel="stylesheet" type="text/css" href="button.css">
<title>Premier Label Express</title> 
<script src = "http://labelwriter.com/software/dls/sdk/js/DYMO.Label.Framework.latest.js" type="text/javascript" charset="UTF-8"> </script>
<script src = "PrintDymoBasic.js" type="text/javascript" charset="UTF-8"> </script>
<script src = "PrintLabel3.js" type="text/javascript" charset="UTF-8"> </script>
</head>
<body>

<div id="headerimage">
<img style="border-width: 0px;" src="Vector%20Logo-L.png" width="437" height="147" alt="Premier Logo" />




	<div id=textDiv">
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Banana')">Banana</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Black Cherry')">Black Cherry</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Blue Cheese')">Blue Cheese</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Blue Raspberry')">Blue Raspberry</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Buffalo Wing')">Buffalo Wing</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Butter')">Butter</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Butter Pecan')">Butter Pecan</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Butter Rum')">Butter Rum</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Cajun')">Cajun</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Caramel Apple')">Caramel Apple</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Caramel Cashew')">Caramel Cashew</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Caramel Chipotle')">Caramel Chipotle</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Caramel Peanut')">Caramel Peanut</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Cheddar')">Cheddar</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Cheesecake')">Cheesecake</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Cherry')">Cherry</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Chicago Mix')">Chicago Mix</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Chocolate Covered Cherry')">Chocolate Covered Cherry</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Chocolate Mocha')">Chocolate Mocha</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Cinnamon')">Cinnamon</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Cinnamon Bun')">Cinnamon Bun</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Confetti')">Confetti</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Creamy Dill')">Creamy Dill</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Garlic Parmesan')">Garlic Parmesan</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Golden Driller')">Golden Driller</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Grape')">Grape</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Green Apple')">Green Apple</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Jalapeno Cheddar')">Jalapeno Cheddar</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Kettle')">Kettle</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Lemon Lime')">Lemon Lime</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Peach')">Peach</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Peanut Butter Chocolate')">Peanut Butter Chocolate</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Pumpkin Pie')">Pumpkin Pie</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Salt & Vinegar')">Salt & Vinegar</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Southwest Jalapeno')">Southwest Jalapeno</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Strawberry')">Strawberry</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Sweet and Cheesy')">Sweet and Cheesy</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Tom's Caramel')">Tom's Caramel</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Tuxedo')">Tuxedo</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('Watermelon')">Watermelon</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('White Cheddar')">White Cheddar</button>
<button id=1printButton class="btn-big-red" onClick="PrintMyDymo('White Chocolate Peppermint')">White Chocolate Peppermint</button>
	
	</div>


	
 <div id="textDiv">
        <label for="textTextArea">Custom Label text:</label><br/>
        <textarea name="textTextArea" id="3textTextArea"  rows='1' cols='40'></textarea>
    </div>



        <div id="printDiv">
            <button id="3printButton">Print Custom</button>
        </div>
	
</body> 
 
</html> 

JavaScript:
//----------------------------------------------------------------------------
//
//  $Id: PreviewAndPrintLabel.js 11419 2010-04-07 21:18:22Z vbuzuev $ 
//
// Project -------------------------------------------------------------------
//
//  DYMO Label Framework
//
// Content -------------------------------------------------------------------
//
//  DYMO Label Framework JavaScript Library Samples: Print label
//
//----------------------------------------------------------------------------
//
//  Copyright (c), 2010, Sanford, L.P. All Rights Reserved.
//
//----------------------------------------------------------------------------


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

        // 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>Small30346</Id>\
        <PaperName>30346 1/2 in x 1-7/8 in</PaperName>\
        <DrawCommands>\
        <RoundRectangle X="0" Y="0" Width="720" Height="2700" Rx="180" Ry="180"/>\
        </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>Center</HorizontalAlignment>\
                <VerticalAlignment>Middle</VerticalAlignment>\
                <TextFitMode>AlwaysFit</TextFitMode>\
                <UseFullFontHeight>True</UseFullFontHeight>\
                <Verticalized>False</Verticalized>\
                <StyledText/>\
        		  <Element>\
          		    <String>textToPrint</String>\
        	        <Attributes>\
                    <Font Family="Cochin" Size="18" Bold="False" Italic="True" Underline="False" Strikeout="False"/>\
		            <ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>\
        		  </Attributes>\
     		   </Element>\
     		 </StyledText>\
 		   </TextObject>\
   		   <Bounds X="326.3998" Y="57.60002" Width="2289.6" Height="580.7999"/>\
  		</ObjectInfo>\
</DieCutLabel>';

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

                // set label text
                label.setObjectText("Text", textTextArea.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;

} ());
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros