DYMO Connect XML for Javascript 打印错误的大小

DYMO Connect XML for Javascript prints wrong size

提问人:jeHaw Services 提问时间:9/29/2023 更新时间:9/30/2023 访问量:43

问:

我正在为客户开发一个 Web 界面,允许他们将条形码标签从他们的 Web 应用程序打印到 DYMO LabelWriter 450。我正在尝试为大标签地址设置它,1-4/10“ x 3-1/2” (36mm x 89mm)。

我正在使用 JavaScript 通过 Dymo 框架进行连接。

多部分问题:

我拥有的 PaperName 元素的标签是错误的。在线资料将其称为 30330,但这是错误的,尺寸太小,条形码总是打印在标签的左下角。

下面是 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>';

有没有人开发了一个使用这个标签的接口(DYMO #50722400)?任何例子,无论多么简单,都会真正有所帮助。

此外,有没有人对 Bounds 元素的 Width 和 Height 属性有明确的操作技巧?我知道它们是小块,但试图弄清楚如何使条形码沿标签的长度居中。我发现消息来源说,通过将宽度设置为 100% 并将 X 设置为 CENTER 可以工作,但是当 XML 中的值错误时,框架会抛出典型的错误。

再次,任何帮助或建议将不胜感激!提前致谢!

JavaScript XML 动态

评论

0赞 jeHaw Services 9/29/2023
也许对反对票的解释会有所帮助?

答:

0赞 jeHaw Services 9/30/2023 #1

我最终编写了一个函数,该函数遍历标签的所有可能数字并找到了它。对于我船上因缺乏 DYMO Connect Framework for JavaScript 的清晰文档而遭受的其他人来说,标签是 30321 Large Label。

对于任何感兴趣的人,这里有一个功能,有点笨拙,因为您的控制台将填满一长串 400 个错误请求错误,直到找到该数字。

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

由于每次迭代失败后都会在控制台中收到 400 错误,因此可以在 for 语句中减少尝试次数。

希望这对我这种情况的其他人有所帮助。这是最后的手段,但找不到任何正确数字的参考资料。