javascriptxmldymo

DYMO Connect XML for Javascript prints wrong size


I am developing a web interface for a client that allows them to print barcode labels from their web app to a DYMO LabelWriter 450. I am trying to set it up for the Large Label Address, 1-4/10" x 3-1/2" (36mm x 89mm).

I am using JavaScript to connect through the Dymo Framework to Connect.

Multi-part question:

The label for the PaperName element that I have is wrong. Online sources refer to it as 30330 but that's wrong, the dimensions are too small and the barcode always print in the lower left of the label.

Here is a sample of the XML

const labelXml = '<?xml version="1.0" encoding="utf-8"?>\
<DieCutLabel Version="8.0" Units="twips">\
    <PaperOrientation>Landscape</PaperOrientation>\
    <Id>Address</Id>\
    <PaperName>???</PaperName>\
    <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/>\
                <Rotation>Rotation0</Rotation>\
                <IsMirrored>False</IsMirrored>\
                <IsVariable>True</IsVariable>\
                <Text>26956-5A5AF</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="0.223333" Y="0.06" Width="???" Height="???" />\
    </ObjectInfo>\
</DieCutLabel>';

Is there anyone who's developed an interface to use this label (DYMO #50722400)? Any example, no matter how simple would really help.

Additionally, has anyone a definite how-to tip for the Width and Height attributes of the Bounds element? I know they're twips, but trying to figure out how to center the barcode along the length of the label. I found sources that said by making the width 100% and X set to CENTER it would work, but the framework throws the typical error when a value in the XML is wrong.

Again, any help or recommendations will be greatly appreciated! Thanks in advance!


Solution

  • I ended up writing a function that looped through all possible numbers for the label and found it. For what it's worth for any others in my boat suffering from the lack of clear documentation for the DYMO Connect Framework for JavaScript, the label is 30321 Large Label.

    For anyone interested, here is the function, a bit clunky in that your console will fill up with a long list of 400 Bad Request errors until the number is found.

    function findDymoLabelNumber() {
    
    if (!dymo) {
        alert('DYMO Label Framework is not installed or not accessible.');
        return;
    }
    
    var found = false,
        addr = 0;
    
    for (addr = 30300; addr <= 30700; addr++) {
    
        try {
    
            const labelXml = '<?xml version="1.0" encoding="utf-8"?>\
    <DieCutLabel Version="8.0" Units="twips">\
        <PaperOrientation>Landscape</PaperOrientation>\
        <Id>Address</Id>\
        <PaperName>' + addr + ' Large Address</PaperName>\
        <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>BarcodeText</LinkedObjectName>\
                    <Rotation>Rotation0</Rotation>\
                    <IsMirrored>False</IsMirrored>\
                    <IsVariable>True</IsVariable>\
                    <Text>26956-5A5AF</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="0.223333" Y="0.06" Width="8000" Height="2000" />\
        </ObjectInfo>\
    </DieCutLabel>';
    
            // Create a label object
            var label = dymo.label.framework.openLabelXml(labelXml);
    
            // Get the default printer
            var printer = dymo.label.framework.getPrinters()[0];
    
            // Check if a printer is available
            if (!printer) {
                alert('No DYMO LabelWriter printers are available.');
                return;
            }
    
            // Print the label
            label.print(printer.name);
    
            // Optional: Provide user feedback that the label is being printed
            //alert('Label is being printed.');
            found = true;
    
        } catch (e) {
            // Continue trying to find the label
        }
    
        if (found == true) break;
    }
    
    if (found == false) {
        console.log('Label was not found');
    } else {
        console.log('Label number is ' + addr);
    } };
    

    Since you receive the 400 error in the console after every failed iteration, you can cut the number of tries down in the for statement.

    Hope this helps someone else in my situation. This was a last resort effort, but there just isn't any references to be found for the correct numbers.