DYMO标签JavaScript打印框架

时间:2015-07-29 10:08:46

标签: javascript dymo

我的项目涉及在Dymo 400 Turbo上打印患者标签。我已经安装了最新的框架DYMO.Label.Framework.latest.js,我正在尝试使用我在网上找到的一种方法来打印标签。我的问题是XML是为地址标签设计的,而不是更长的患者标签。当我发送到打印机时,它会超过下一个标签,浪费一个。另外,我想在条形码中打印ID而不是地址或邮政编码。有人有什么想法吗?

这是我的XML:

 '<?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>\
                            <AddressObject>\
                                <Name>Address</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>\
                                    <Element>\
                                        <Attributes>\
                                            <Font Family="Arial" Size="8" Bold="False" Italic="False" Underline="False" Strikeout="False" />\
                                            <ForeColor Alpha="255" Red="0" Green="0" Blue="0" />\
                                        </Attributes>\
                                    </Element>\
                                </StyledText>\
                                <LineFonts>\
                                    <Font Family="Arial" Size="8" Bold="False" Italic="False" Underline="False" Strikeout="False" />\
                                    <Font Family="Arial" Size="8" Bold="False" Italic="False" Underline="False" Strikeout="False" />\
                                    <Font Family="Arial" Size="8" Bold="False" Italic="False" Underline="False" Strikeout="False" />\
                                </LineFonts>\
                            </AddressObject>\
                            <Bounds X="332" Y="150" Width="4455" Height="1260" />\
                        </ObjectInfo>\
                    </DieCutLabel>'

我用这个加载标签:

 var label = dymo.label.framework.openLabelXml(labelXml);
    var labelToPrint = getLabelToPrint();
    if (!label) {
        $("#lblError").text("There is no information entered to print");
        $("#MessageDialog").dialog({ title: "No Information" });
        $("#MessageDialog").dialog("open");
        return;
    }
    if (label.getAddressObjectCount() > 0) {
        var add = label.getAddressText(0);
        label.setAddressText(0, labelToPrint);
    }
    // set data using LabelSet and text markup
    var labelSet = new dymo.label.framework.LabelSetBuilder();

    var textMarkup = '';
    var fontSize = 18; // sets font size of first line


    if (labelToPrint == '') {
        $("#lblError").text("There is no information entered to print");
        $("#MessageDialog").dialog({ title: "No Information" });
        $("#MessageDialog").dialog("open");
        return false;
    }
    else {
        var lines = labelToPrint.split('\n');
        var boldLinesCount = lines.length <= 3 ? 1 : 2;
        for (var x = 0; x < lines.length; x++) {
            textMarkup += lines[x] + '\n';
        }
        //textMarkup += lines[0] + '\n';
        //textMarkup += lines[1] + '\n';
        //textMarkup += lines[2];
        label.setAddressText(0, textMarkup);
        //label.setObjectText("Barcode", lines[0]);
        label.setObjectText("Address", textMarkup);
        var record = labelSet.addRecord();
        record.setTextMarkup('Text', textMarkup); // set label text 
    }

2 个答案:

答案 0 :(得分:3)

Dymo LabelWriter 450. 2016年世界上这台打印机和文档都颠倒了。这是一场地狱和噩梦。 DYMO?请记录好。

第1步:

A)获取最新版本的Javascript库和驱动程序

enter image description here enter image description here

B)旧版本搞砸了,浪费时间。 C)更好的开始:http://developers.dymo.com/2016/01/05/dymo-label-software-version-8-5-3-for-patch-release-macwin/

第2步:复制粘贴,然后微笑。

<html>
<head>

<script type="text/javascript" src="http://www.labelwriter.com/software/dls/sdk/js/DYMO.Label.Framework.2.0.2.js"></script>
<script type="text/javascript">
function startupCode() {
  var printers = dymo.label.framework.getPrinters();
  if (printers.length == 0)
    throw "No DYMO printers are installed. Install DYMO printers.";

  dymo.label.framework.getPrintersAsync().then(function(printers){
    // Successful result, printers variable has a list of all supported by the DYMO Label Framework
    console.log(printers);
  }).thenCatch(function(error){
    // Error
  });

   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>True</IsVariable>\
            <Text></Text>\
            <Type>Code39</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="331" Y="178" Width="4260" Height="420" />\
    </ObjectInfo>\
</DieCutLabel>';    

  var label = dymo.label.framework.openLabelXml(labelXml);
  label.setObjectText("BARCODE", '000220200');
  label.print("DYMO LabelWriter 450"); // This is the NAME of the printer which i found 
}
function frameworkInitShim() {
  dymo.label.framework.trace = 1; //true
  dymo.label.framework.init(startupCode); 
}
window.onload = frameworkInitShim;
</script>

</head>
<body>


</body>
</html>

步骤3:正确打印,控制台输出正确调试。

enter image description here

enter image description here

答案 1 :(得分:0)

我通过将此问题添加到XML来修复此问题:

 <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>True</IsVariable>\
            <Text></Text>\
            <Type>Code39</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="331" Y="178" Width="4260" Height="420" />\
    </ObjectInfo>\

然后在函数中:

 label.setObjectText("BARCODE", lines[0]);

这是条形码中我想要的项目。