Print ALL button to run three other print buttons java-html-dymo printer

Hi Experts
Need your help I am using the dymo Label printer it comes with DYMO Label Framework JavaScript Library Samples…
 On the HTML page there is 3 text input boxes  and 3 print buttons. Each print button  links to a PrintLabel.js script and prints the relevant text box onto a label.
What I need is a print button that will print all 3 text boxes at once so I don’t have to select each print button under each textbox

Thanks Experts

Html Code
<!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 1-2-3</title> 
<script src = "http://labelwriter.com/software/dls/sdk/js/DYMO.Label.Framework.latest.js" type="text/javascript" charset="UTF-8"> </script>
<script src = "PrintLabel1.js" type="text/javascript" charset="UTF-8"> </script>
<script src = "PrintLabel2.js" type="text/javascript" charset="UTF-8"> </script>
<script src = "PrintLabel3.js" type="text/javascript" charset="UTF-8"> </script>
</head>

<body>
<h1>DYMO Label Framework JavaScript Library Samples: Print Label test 1</h1> 


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



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

		
		
		
		<h1>DYMO Label Framework JavaScript Library Samples: Print Label test 2</h1> 


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



        <div id="printDiv">
            <button id="2printButton">Print</button>
        </div>
		
		
		<h1>DYMO Label Framework JavaScript Library Samples: Print Label test 3</h1> 


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



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

Open in new window


As you can see the only difference is line 25 and 26 in each PrintLable.js

PrintLable1.js
//----------------------------------------------------------------------------
//
//  $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('1textTextArea');
        var printButton = document.getElementById('1printButton');

        // 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>\
    </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;

} ());

Open in new window


PrintLable2.js
//----------------------------------------------------------------------------
//
//  $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('2textTextArea');
        var printButton = document.getElementById('2printButton');

        // 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>\
    </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;

} ());

Open in new window


PrintLable3.js

//----------------------------------------------------------------------------
//
//  $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>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>\
    </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;

} ());

Open in new window

paddy086Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chaauCommented:
You will need to change your PrintLabel1.js, PrintLabel2.js and PrintLabel3.js to use an Event Interface function instead of the Dom Element Properties. Check this article for more info. In addition, to follow the DRY (or DIE) principle you need to avoid repeating the whole chunk of code with only a couple of lines of difference. You need to refactor.
So, modify your js files to a single printLable.js file, like this:
function printStuff(what)
{
            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>\
    </DieCutLabel>';
                var label = dymo.label.framework.openLabelXml(labelXml);

                // set label text
                label.setObjectText("Text", what);
                
                // 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);
            }
}
function print1()
{
    var textTextArea = document.getElementById('1textTextArea');
    printStuff(textTextArea.value);
}
function print2()
{
    var textTextArea = document.getElementById('2textTextArea');
    printStuff(textTextArea.value);
}
function print3()
{
    var textTextArea = document.getElementById('3textTextArea');
    printStuff(textTextArea.value);
}

Open in new window

And your buttons in the HTML will become (add your other HTML elements there):
        <div id="printDiv">
            <button id="1printButton" onclick="print1();return false;">Print</button>
        </div>
        <div id="printDiv">
            <button id="2printButton" onclick="print2();return false;">Print</button>
        </div>
        <div id="printDiv">
            <button id="3printButton" onclick="print3();return false;">Print</button>
        </div>
        <div id="printAll">
            <button id="printAllBtn" onclick="print1(); print2(); print3(); return false">Print All</button>
        </div>

Open in new window

0
paddy086Author Commented:
Hi chaau

I have tried to edit my code the way you suggested but i cant get it to work
//----------------------------------------------------------------------------
//
//  $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('1textTextArea');
        var printButton = document.getElementById('1printButton');

        // 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>\
    </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;

} ());

Open in new window


<!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 = "PrintLabelnew.js" type="text/javascript" charset="UTF-8"> </script>
</head>

<body>
<h1>DYMO Label Framework JavaScript Library Samples: Print Label test 2</h1> 


    <div id="printDiv">
	<label for="textTextArea">Label text:</label><br/>
        <textarea name="textTextArea" id="textTextArea"  rows='5' cols='40'></textarea>
            <button id="1printButton" onclick="print1();return false;">Print</button>
        </div>
		
        <div id="printDiv">
		<label for="textTextArea">Label text:</label><br/>
        <textarea name="textTextArea" id="textTextArea"  rows='5' cols='40'></textarea>
            <button id="2printButton" onclick="print2();return false;">Print</button>
        </div>
        <div id="printDiv">
		<label for="textTextArea">Label text:</label><br/>
        <textarea name="textTextArea" id="textTextArea"  rows='5' cols='40'></textarea>
            <button id="3printButton" onclick="print3();return false;">Print</button>
        </div>
        <div id="printAll">
            <button id="printAllBtn" onclick="print1(); print2(); print3(); return false">Print All</button>
        </div>

</body> 
 
</html> 

Open in new window

0
paddy086Author Commented:
I think its safe to say I haven't got a clue what to do to make this work .....
I need more help thnaks
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

chaauCommented:
You are almost there. HTML source looks right. Put this code into your printLabelNew.js:
function printStuff(what)
{
            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>\
    </DieCutLabel>';
                var label = dymo.label.framework.openLabelXml(labelXml);

                // set label text
                label.setObjectText("Text", what);
                
                // 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);
            }
}
function print1()
{
    var textTextArea = document.getElementById('1textTextArea');
    printStuff(textTextArea.value);
}
function print2()
{
    var textTextArea = document.getElementById('2textTextArea');
    printStuff(textTextArea.value);
}
function print3()
{
    var textTextArea = document.getElementById('3textTextArea');
    printStuff(textTextArea.value);
}
                                          

Open in new window

0
paddy086Author Commented:
Hi Chaau thanks for the help.. I have attached what I have done so far but it dose not print using any of the print buttons

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 = "PrintLabelnew.js" type="text/javascript" charset="UTF-8"> </script>
</head>

<body>
<h1>DYMO Label Framework JavaScript Library Samples: Print Label test 2</h1> 


    <div id="printDiv">
	<label for="textTextArea">Label text:</label><br/>
        <textarea name="textTextArea" id="textTextArea"  rows='5' cols='40'></textarea>
            <button id="1printButton" onclick="print1();return false;">Print</button>
        </div>
		
        <div id="printDiv">
		<label for="textTextArea">Label text:</label><br/>
        <textarea name="textTextArea" id="textTextArea"  rows='5' cols='40'></textarea>
            <button id="2printButton" onclick="print2();return false;">Print</button>
        </div>
        <div id="printDiv">
		<label for="textTextArea">Label text:</label><br/>
        <textarea name="textTextArea" id="textTextArea"  rows='5' cols='40'></textarea>
            <button id="3printButton" onclick="print3();return false;">Print</button>
        </div>
        <div id="printAll">
            <button id="printAllBtn" onclick="print1(); print2(); print3(); return false">Print All</button>
        </div>

</body> 
 
</html>

Open in new window


and the
PrintLabelnew.js
//----------------------------------------------------------------------------
//
//  $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 printStuff(what)
{
            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>\
    </DieCutLabel>';
                var label = dymo.label.framework.openLabelXml(labelXml);

                // set label text
                label.setObjectText("Text", what);
                
                // 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);
            }
}
function print1()
{
    var textTextArea = document.getElementById('1textTextArea');
    printStuff(textTextArea.value);
}
function print2()
{
    var textTextArea = document.getElementById('2textTextArea');
    printStuff(textTextArea.value);
}
function print3()
{
    var textTextArea = document.getElementById('3textTextArea');
    printStuff(textTextArea.value);
}
 ());

Open in new window

0
chaauCommented:
you need to make the id's of the textAreas to 1textTextArea, 2textTextArea and 3textTextArea:
<!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 = "PrintLabelnew.js" type="text/javascript" charset="UTF-8"> </script>
</head>

<body>
<h1>DYMO Label Framework JavaScript Library Samples: Print Label test 2</h1> 


    <div id="printDiv">
	<label for="textTextArea">Label text:</label><br/>
        <textarea name="textTextArea" id="1textTextArea"  rows='5' cols='40'></textarea>
            <button id="1printButton" onclick="print1();return false;">Print</button>
        </div>
		
        <div id="printDiv">
		<label for="textTextArea">Label text:</label><br/>
        <textarea name="textTextArea" id="2textTextArea"  rows='5' cols='40'></textarea>
            <button id="2printButton" onclick="print2();return false;">Print</button>
        </div>
        <div id="printDiv">
		<label for="textTextArea">Label text:</label><br/>
        <textarea name="textTextArea" id="3textTextArea"  rows='5' cols='40'></textarea>
            <button id="3printButton" onclick="print3();return false;">Print</button>
        </div>
        <div id="printAll">
            <button id="printAllBtn" onclick="print1(); print2(); print3(); return false">Print All</button>
        </div>

</body> 
 
</html>

Open in new window

Also, you need to remove the last line from the javasript file:
 ());

Open in new window

0
paddy086Author Commented:
Hi chaau

Did that still not printing from any buttons
0
paddy086Author Commented:
Chaau

Could it be down to the way Dymo Label Printers work that is stopping the print when you use only one PrintLable.js

and if so then going back to my first post that had PrintLable1.js  PrintLable2.js  PrintLable3.js
is there any way of adding a print all button to that HTML page
0
chaauCommented:
Can you debug? What browser do you use? If IE turn F12 developer tools and set the breakpoint on the entry of printStuff() function. See if it gets called.
0
paddy086Author Commented:
Untitled.png
0
chaauCommented:
Have you placed the PrintLabelnew.js to the same folder where your testprint2.html is located? If not, modify the path in this line:
<script src = "PrintLabelnew.js" type="text/javascript" charset="UTF-8"> </script>

Open in new window

0
paddy086Author Commented:
yep Chaau

Both files are in same folder
0
chaauCommented:
In the debugger scroll to the top of the page. Locate the line with the "<script src = "PrintLabelnew.js"" double click on the src. Check if the javascript file opens. I have just created the html and the js file on my PC. Works fine
0
chaauCommented:
Extract the content of the zip file to a new folder test the file inside
Temp.zip
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
paddy086Author Commented:
chaau
Thank you it worked. it was my fault it was the PrintLabelnew.js name some were in my editing of the js script I changed the name to PrintLabelnew.js.js

thank you for all your help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.