gpt4 book ai didi

javascript - Dymo Framework 条形码打印

转载 作者:行者123 更新时间:2023-11-27 23:27:29 25 4
gpt4 key购买 nike

首先让我说这些是我一直试图解决在 Dymo 450 LabelWriter 标签上打印条形码的问题的所有网站和地点。

http://developers.dymo.com/2010/06/02/dymo-label-framework-javascript-library-samples-print-a-label/ DYMO label JavaScript printing framework http://developers.dymo.com/2010/03/24/understanding-label-file-formats-in-dymo-label-v-8-label-objects/ Printing in Java to Label Printer

dymo 网站对我来说是一团糟。我无法得到我正在寻找的任何东西的直接答案。我试图从他们的标签站点拼凑代码并且它有效。我想在标签上添加条形码。

这是我尝试过的:

打印标签.js

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

// 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="160" />\
</ObjectInfo>\
<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="224" Y="150" Width="150" Height="120" />\
</ObjectInfo>\
</DieCutLabel>';
var label = dymo.label.framework.openLabelXml(labelXml);

// set label text
label.setObjectText("Text", textTextArea.value);
label.setObjectText("BARCODE", '721');

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

} ());

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

<body>
<h2>Lab Label</h2>

<div id="textDiv">
<label for="textTextArea">Label :</label><br/>
<textarea name="textTextArea" id="textTextArea" rows='5' cols='20'>
<?php echo $name ."\n"; ?>
<?php echo date("Y-m-d") . "&#160;&#160;&#160;&#160;&#160;&#160;" .$oid."\n"; ?>


</textarea>

<input type="text" id="barCode" value="786">
</div>

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

</body>

</html>

我添加的内容 http://developers.dymo.com/2010/03/24/understanding-label-file-formats-in-dymo-label-v-8-label-objects/

site 是 Barcode 对象。我以为我可以把它放进去,然后就可以了。但我注意到 TextObject 代码似乎也没有做太多事情。

如有任何建议,我们将不胜感激。

最佳答案

这是现在可用于 Print.js 文件的最终代码。

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

// 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>\
<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>barCode</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="324" Y="950" Width="3150" Height="520" />\
</ObjectInfo>\
</DieCutLabel>';
var label = dymo.label.framework.openLabelXml(labelXml);

// set label text
label.setObjectText("Text", textTextArea.value);
label.setObjectText('Barcode', barCode.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;

} ());

关于javascript - Dymo Framework 条形码打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37666730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com