一开始,让我说这些都是我一直试图找出在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网站给我带来了很大的麻烦。我无法直接回答我正在寻找的任何事情。我试图将标签网站上的代码拼凑起来,但它确实有用。我想在标签上添加条形码。
以下是我的尝试:
PrintLabel.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") . "      " .$oid."\n"; ?>
</textarea>
<input type="text" id="barCode" value="786">
</div>
<div id="printDiv">
<button id="printButton">Print</button>
</div>
</body>
</html>
网站是条形码对象。我以为我可以把它放进去就可以了。但我注意到TextObject代码似乎也没有做太多。
任何建议都将不胜感激。
答案 0 :(得分:2)
以下是适用于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;
} ());