用Java編寫一個(gè)打印標(biāo)簽客戶端
?點(diǎn)擊運(yùn)行啟動(dòng)會(huì)打開首頁(yè)
?可以點(diǎn)擊預(yù)覽打印?
點(diǎn)擊打印可測(cè)試成功?
?
?打印機(jī)結(jié)果
?前端用的是thymeleaf
代碼片段
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>首頁(yè)</title>
<link rel="icon" th:href="@{/title.ico}" type="image/x-icon"/>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" >
<script src="https://cdn.staticfile.org/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="col-sm-12 column">
<ol class="breadcrumb">
<li class="active">打印機(jī)客戶端
</li>
<li class="active">打印機(jī)管理
</li>
</ol>
<!-- <a th:href="@{/printService/download}">操作手冊(cè).PDF</a> <br/>-->
<div class="table-responsive">
<table class="table table-striped ">
<thead>
<tr>
<th style="text-align:center">打印機(jī)名稱</th>
<th style="text-align:center">打印機(jī)狀態(tài)</th>
</tr>
</thead>
<tbody>
<!--
這里的 policyPublishDetailDtoList
是 Controller 通過 model.addAttribute("policyPublishDetailDtoList", list);傳過來的
th:each th:text都是thymeleaf中常用的標(biāo)簽
-->
<tr th:each="printInfoDto:${printInfoVoDtoList}">
<td th:text="${printInfoDto.printName}" style="text-align:center;vertical-align:middle;"></td>
<td th:text="${printInfoDto.printStatus}" style="text-align:center;vertical-align:middle;"></td>
<td>
<div class="btn-group" th:if="${printInfoDto.status}">
<a class="btn btn-default" th:href="@{/printService/preview(printName=${printInfoDto.printName})}" th:text="${'預(yù)覽 | ' + printInfoDto.printName}"></a>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
后端代碼文章來源:http://www.zghlxwxcb.cn/news/detail-613381.html
/**
* 得到全部打印機(jī)
*/
@GetMapping("/printList")
public String printList(Model model, HttpServletRequest request) {
PrintInfoVo printInfoVo;
List<PrintInfoVo> printInfoVoList = new ArrayList<>();
List<String> totalPrinterList = PrintUtils.getTotalPrinterList();
if (totalPrinterList.size() > 0) {
//在線打印機(jī)
Map<String, String> map = PrintUtils.getZxPrinterMap();
//默認(rèn)打印機(jī)
String defaultPrintName = PrintUtils.getDefaultPrintName();
// 遍歷所有打印機(jī)的名稱
for (String printer : totalPrinterList) {
printInfoVo = new PrintInfoVo();
printInfoVo.setStatus(false);
if (printer.equals(defaultPrintName)) {//默認(rèn)打印機(jī)
printInfoVo.setPrintName(printer);
String PrintStatus = "默認(rèn)打印機(jī)";
if (map.get(printer) == null) {
printInfoVo.setPrintStatus(PrintStatus + "-脫機(jī)");
} else {
printInfoVo.setPrintStatus(PrintStatus + "-在線");
printInfoVo.setStatus(true);
}
} else {//其他打印機(jī)
printInfoVo.setPrintName(printer);
if (map.get(printer) == null) {
printInfoVo.setPrintStatus("脫機(jī)");
} else {
printInfoVo.setPrintStatus("在線");
}
}
printInfoVoList.add(printInfoVo);
}
}
model.addAttribute("printInfoVoDtoList", printInfoVoList);
model.addAttribute("printInfoDto", new PrintInfoVo());
request.getSession().removeAttribute("relativePath");
return "printList";
}
/**
* 打印標(biāo)簽
*/
@GetMapping("/testPrint")
public String testPrint(String printName, Model model, HttpServletRequest request) {
//調(diào)用打印邏輯進(jìn)行打印
PrintServer printServer = new PrintServer();
Result result = printServer.print(PrintUtils.InitialDateString);
model.addAttribute("printName", printName);
model.addAttribute("result", result.getMsg());
request.getSession().removeAttribute("relativePath");
return "result";
}
?頁(yè)面上預(yù)覽圖片和真實(shí)打印機(jī)打出來的不一致是正常的因?yàn)檫@是測(cè)試打?。y(cè)試本地電腦是否符合使用打印機(jī)客戶端調(diào)用bartender進(jìn)行打印)文章來源地址http://www.zghlxwxcb.cn/news/detail-613381.html
到了這里,關(guān)于JAVA調(diào)用Bartender進(jìn)行標(biāo)簽打?。杀镜赜么蛴C(jī)客戶端進(jìn)行測(cè)試打印,【云上的項(xiàng)目】可通過WebSocket進(jìn)行通訊進(jìn)行打?。┑奈恼戮徒榻B完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!