Printing Multiple Labels from PHP/Web Application to Dymo LabelWriter 450 Turbo

6.6k views Asked by At

I'm looking to add the functionality to print multiple labels using a Dymo LabelWriter 450 Turbo. I've downloaded the DYMO-Label-v.8-SDK.dmg from the Dymo site but can't see any Javascript/web related SDK files or documentation - all I can see are AppleScript examples which won't help here.

Does anyone know if this is possible (data for labels will come from backend database connected to PHP web app). I can't find any documentation for a Javascript SDK on the Dymo Developer website - only some examples from a few years ago so not even sure what is the current state and which is the latest version etc and whether there is a way to print multiple labels?

1

There are 1 answers

1
MostlyRquestions On BEST ANSWER

I actually just built this functionality in my own web app using the exact same printer and I'm feeling friendly today. Here is what I have working for me in a production level application. Good luck!

HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>DYMO: QR-code</title> 
<!-- JQuery -->
<script src = "http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript" charset="UTF-8"> </script>
<!-- Dymo Script -->
<script src="DYMO.Label.Framework.2.0.2.js" type="text/javascript" charset="UTF-8"></script>
<!-- QR Code -->
<script src="QRCode.js" type="text/javascript" charset="UTF-8"> </script>
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>


</head>

<body>

<div class="container">

    <div class="jumbotron">
        <h3>DYMO Label Framework JavaScript Library Samples: QR code</h3> 
        <div class="header">
            <div id="sampleDesctiption">
                <span>
                    This sample shows different ways to print a label with a QR-code barcode.
                </span>
            </div>
        </div>
    </div>


    <div class="container">
        <div class="printControls">

            <div class="row">
                <div class="col-md-6">
                    <div id="printersDiv">
                        <label for="printersSelect">Printer:</label><br/>
                        <select class="form-control" id="printersSelect"></select>
                    </div>
                </div>
            </div>

            <div id="printDiv" style="padding-top:20px">
                <button class="btn btn-primary btn-lg" id="printButton">Print QR Code</button>
            </div>

        </div>
    </div>

</div>



</body> 

</html> 

QRCode.js

// stores loaded label info
var barcodeLabel;

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

    // loads all supported printers into a combo box 
    function loadPrinters() {
        var printers = dymo.label.framework.getLabelWriterPrinters();
        if (printers.length == 0) {
            alert("No DYMO printers are installed. Install DYMO printers.");
            return;
        }
        console.log("got here: ", printers );

        for (var i = 0; i < printers.length; i++) {
            var printer = printers[i];

            var printerName = printer.name;

            var option = document.createElement('option');
            option.value = printerName;
            option.appendChild(document.createTextNode(printerName));
            printersSelect.appendChild(option);
        }
    }

    printButton.onclick = function () {
            var label_text = 'QRCode Text Here..';

            barcodeLabel.setObjectText('Barcode', label_text);

            // Should Be Printer Name, Dymo 450 Turbo..
            console.log("print: ", printersSelect.value );

            barcodeLabel.print( printersSelect.value );

    }

    function getBarcodeLabelXml() {

        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>False</IsVariable>\
                                        <Text></Text>\
                                        <Type>QRCode</Type>\
                                        <Size>Small</Size>\
                                        <TextPosition>None</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="300" Right="600" Bottom="0" />\
                                    </BarcodeObject>\
                                    <Bounds X="331" Y="57.9999999999999" Width="2880" Height="1435" />\
                                </ObjectInfo>\
                            </DieCutLabel>';
        return labelXml;
    }

    function loadLabelFromWeb() {
        barcodeLabel = dymo.label.framework.openLabelXml( getBarcodeLabelXml() );
    }

    // Load Labels 
    loadLabelFromWeb();

    // load printers list on startup
    loadPrinters();
};

// Run's Dymo Javascript.. 
dymo.label.framework.init(onload);