gpt4 book ai didi

javascript - Dymo 网络打印 java.html

转载 作者:行者123 更新时间:2023-12-03 11:43:04 24 4
gpt4 key购买 nike

我正在使用 dymo 打印机,这是他们提供的用于启用 Web 打印的代码。我已将其编辑为具有 3 个文本框,这样我可以一次打印 3 个标签。我的问题是:当我按下打印按钮时,它只打印第一个文本框。

我需要的是打印所有 3 个测试框。另外,如果代码可以编辑,如果其中一个框留空,脚本将跳过该框,只打印其中包含文本的文本框。

<!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>
<h1>DYMO Label Framework JavaScript Library Samples: Print Label test 2</h1>

<table>
<tr>
<td><p>


<div id="textDiv">
<label for="textTextArea">Label text:</label><br/>
<textarea name="textTextArea" id="textTextArea" rows='5' cols='40'></textarea>
</div>

</p></td>






<td><p>


<div id="textDiv">
<label for="textTextArea">Label text:</label><br/>
<textarea name="textTextArea" id="textTextArea" rows='5' cols='40'></textarea>
</div>

</p></td>











<td><p>


<div id="textDiv">
<label for="textTextArea">Label text:</label><br/>
<textarea name="textTextArea" id="textTextArea" rows='5' cols='40'></textarea>
</div>

</p></td>
</tr>
</table>

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

</body>

</html>

抱歉,这是 PrintLable.js

//----------------------------------------------------------------------------
//
// $Id: PreviewAndPrintLabel.js 11419 2010-04-07 21:18:22Z vbuzuev $
//
// Project -------------------------------------------------------------------
//
// DYMO Label Framework
//
// Content -------------------------------------------------------------------
//
// DYMO Label Framework JavaScript Library Samples: Print label
//
//----------------------------------------------------------------------------
//
// Copyright (c), 2010, Sanford, L.P. All Rights Reserved.
//
//----------------------------------------------------------------------------


(function()
{
// called when the document completly loaded
function onload()
{
var textTextArea = document.getElementById('textTextArea');
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>\
</DieCutLabel>';
var label = dymo.label.framework.openLabelXml(labelXml);

// set label text
label.setObjectText("Text", textTextArea.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 函数。

var process_labels = function(label_DOM_element){

var textTextArea = label_DOM_element.getElementById('textTextArea');

print_label(textTextArea);
}

然后,您需要将标签 JS 更改为触发函数,而不是在主体加载时加载。此外,您还需要允许传入参数。

所以而不是

//打印标签
printButton.onclick = function()

将其更改为类似于以下的函数:

 var print_label = function(textTextArea){
{
// 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>\
</DieCutLabel>';

ETC ETC...
}

我不会为您写出全部内容,但基本上您将拥有一个按钮单击函数,该函数将检查“textDiv”的所有元素并将它们中的每个元素传递到 process_label 函数中。

涉及到一些工作,但您的 javascrtipt 目前只需要 1 个元素,因此您需要创建一个可以按需调用的函数。

关于javascript - Dymo 网络打印 java.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26176511/

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