|
<html> |
|
|
|
<head> |
|
<script src="DYMO.Label.Framework.2.0.2.js"></script> |
|
<script> |
|
// Busy wait sleep function. |
|
function sleep(seconds){ |
|
var waitUntil = new Date().getTime() + seconds*1000; |
|
while(new Date().getTime() < waitUntil) true; |
|
} |
|
|
|
dymo.label.framework.init(function() { |
|
try |
|
{ |
|
// open label |
|
var labelXml = '<?xml version="1.0" encoding="utf-8"?>\n' + |
|
'<DieCutLabel Version="8.0" Units="twips" MediaType="Default">\n' + |
|
'\t<PaperOrientation>Landscape</PaperOrientation>\n' + |
|
'\t<Id>LargeShipping</Id>\n' + |
|
'\t<IsOutlined>false</IsOutlined>\n' + |
|
'\t<PaperName>30256 Shipping</PaperName>\n' + |
|
'\t<DrawCommands>\n' + |
|
'\t\t<RoundRectangle X="0" Y="0" Width="3331" Height="5715" Rx="270" Ry="270" />\n' + |
|
'\t</DrawCommands>\n' + |
|
'\t<ObjectInfo>\n' + |
|
'\t\t<TextObject>\n' + |
|
'\t\t\t<Name>name</Name>\n' + |
|
'\t\t\t<ForeColor Alpha="255" Red="0" Green="0" Blue="0" />\n' + |
|
'\t\t\t<BackColor Alpha="0" Red="255" Green="255" Blue="255" />\n' + |
|
'\t\t\t<LinkedObjectName />\n' + |
|
'\t\t\t<Rotation>Rotation0</Rotation>\n' + |
|
'\t\t\t<IsMirrored>False</IsMirrored>\n' + |
|
'\t\t\t<IsVariable>False</IsVariable>\n' + |
|
'\t\t\t<GroupID>-1</GroupID>\n' + |
|
'\t\t\t<IsOutlined>False</IsOutlined>\n' + |
|
'\t\t\t<HorizontalAlignment>Center</HorizontalAlignment>\n' + |
|
'\t\t\t<VerticalAlignment>Middle</VerticalAlignment>\n' + |
|
'\t\t\t<TextFitMode>AlwaysFit</TextFitMode>\n' + |
|
'\t\t\t<UseFullFontHeight>True</UseFullFontHeight>\n' + |
|
'\t\t\t<Verticalized>False</Verticalized>\n' + |
|
'\t\t\t<StyledText>\n' + |
|
'\t\t\t\t<Element>\n' + |
|
'\t\t\t\t\t<String xml:space="preserve">Name</String>\n' + |
|
'\t\t\t\t\t<Attributes>\n' + |
|
'\t\t\t\t\t\t<Font Family="Arial" Size="24" Bold="True" Italic="False" Underline="False" Strikeout="False" />\n' + |
|
'\t\t\t\t\t\t<ForeColor Alpha="255" Red="0" Green="0" Blue="0" HueScale="100" />\n' + |
|
'\t\t\t\t\t</Attributes>\n' + |
|
'\t\t\t\t</Element>\n' + |
|
'\t\t\t</StyledText>\n' + |
|
'\t\t</TextObject>\n' + |
|
'\t\t<Bounds X="336" Y="1080" Width="5010" Height="1020" />\n' + |
|
'\t</ObjectInfo>\n' + |
|
'</DieCutLabel>'; |
|
|
|
var label = dymo.label.framework.openLabelXml(labelXml); |
|
|
|
// set label text |
|
label.setObjectText("name", "Scott Vitale"); |
|
|
|
// 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."; |
|
} |
|
|
|
// Build a LabelSetBuilder object and update the dynamic record. |
|
var labelSetBuilder = new dymo.label.framework.LabelSetBuilder(); |
|
var record = labelSetBuilder.addRecord(); |
|
|
|
for (var i = 0; i < printers.length; ++i) |
|
{ |
|
if (printers[i].printerType === "LabelWriterPrinter") |
|
{ |
|
// Print a label on every printer |
|
record.setTextMarkup("name", "Scott " + i.toString()); |
|
label.print(printers[i].name); |
|
} |
|
} |
|
} |
|
catch(e) |
|
{ |
|
alert(e.message || e); |
|
} |
|
}); |
|
|
|
console.log('done.'); |
|
</script> |
|
</head> |
|
</html> |
This comment has been minimized.
Both of these examples (Javascript and C#) complete successfully, but the printers do NOT print the labels. Sometimes a label gets sent to the wrong printer, sometimes they don't come out at all, sometimes Windows chokes and shows error/offline status for all printers.