打印尝试2

This commit is contained in:
2026-04-02 17:43:48 +08:00
parent b2c102fc80
commit 791096107f
3 changed files with 41 additions and 14 deletions

View File

@@ -54,8 +54,9 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl {
.setCenterBold(new String[]{"<CB>", "</CB>"})
.setF(new String[]{"<F>", "</F>"})
.setL(new String[]{"<L>", "</L>"})
.setS(new String[]{"", ""})
.setF(new String[]{"<B>", "</B>"})
.setS(new String[]{"<s>", "</s>"})
.setS(new String[]{"<s>", "</s>"})
.setRight(new String[]{"<RIGHT>", "</RIGHT>"})
.setQr(new String[]{"<QR>", "</QR>"})
.setCenter(new String[]{"<C>", "</C>"})
.setBold(new String[]{"<BOLD>", "</BOLD>"});

View File

@@ -28,6 +28,32 @@ public interface PrinterImpl {
@Data
@Accessors(chain = true)
class PrintSignLabel {
/**
* <BR> :换行符
* <CUT> :切刀指令/自动走纸(主动切纸,仅限切刀打印机使用才有效果/手动撕纸设备使用该指令时为自动走纸)
* <LOGO> 打印LOGO指令(有该指令则会打印LOGO设备首次使用需上传LOGO图片)
* <PLUGIN> :预留
* <S></S>缩小字体对应24*24字体默认字体大小为32*32
* <F></F>放大字体对应48*48字体
* <CB></CB>设置字体64*64且居中
* <B></B>放大一倍对应64*64字体
* <C></C>:居中
* <L></L>:字体变高一倍
* <W></W>:字体变宽一倍
* <QR></QR>:二维码(单个订单,最多只能打印一个二维码)
* <BC128_A></BC128_A>:数字字母混合条形码
* <RIGHT></RIGHT>:右对齐
* <BOLD></BOLD>:字体加粗
* <UDL></UDL>: 设置下划线打印
* <HL></HL>: 反白打印
* <RT:?></RT>: 字符旋转(“?”代表旋转角度)
* <RS:?>: 此行到下行的行间距“?”该值可自己设置最小1最大127不设置则为默认
* <WS:?>: 每行中文字的间距“?”该值可自己设置最小1最大48不设置则为默认
* <CS:x>:设置可变字体大小</CS>x16,24,32,48,64,72,96都可支持如x=96则为96*96字体
* <OUT:113>:走纸113点
* <PLUGIN>:切刀全切指令(只适用带切刀型设备)
* <PCUT>:切刀半切指令(只适用带切刀型设备)
*/
private String[] center;
private String[] centerBold;
private String[] bold;
@@ -36,6 +62,7 @@ public interface PrinterImpl {
private String[] f;
private String[] l;
private String[] qr;
private String[] Right;
private String cut;
private String out;
private String rs;
@@ -108,7 +135,6 @@ public interface PrinterImpl {
// 品名可以在一行显示,直接补足空格
title = titleAddSpace(title, b1);
sb.append(getFormatLabel(title + otherStr, signLabelInfo.s));
// sb.append(startSplitSign).append(title).append(otherStr).append(endSplitSign);
} else {
// 品名超出一行,进行拆分
List<String> lines = isEn(title)
@@ -119,22 +145,16 @@ public interface PrinterImpl {
// 第一行拼接其它字段
String firstLine = titleAddSpace(lines.getFirst(), b1);
// sb.append(startSplitSign).append(firstLine).append(otherStr).append(endSplitSign).append("<BR>");
sb.append(getFormatLabel(firstLine + otherStr, signLabelInfo.s));
sb.append(signLabelInfo.br);
// 剩余的行单独换行输出
for (int i = 1; i < lines.size(); i++) {
if (i + 1 != lines.size()) {
// sb.append(signLabelInfo.getRs(1));
sb.append(getFormatLabel(titleAddSpace(lines.get(i), b1), signLabelInfo.s));
sb.append(signLabelInfo.br);
} else {
sb.append(getFormatLabel(titleAddSpace(lines.get(i), b1), signLabelInfo.s));
}
// sb.append(startSplitSign).append(lines.get(i)).append(endSplitSign).append("BR>");
}
}
sb.append(signLabelInfo.br);
@@ -243,8 +263,8 @@ public interface PrinterImpl {
for (OrderDetail detail : detailList) {
String number = detail.getNum().stripTrailingZeros().toPlainString();
String row = getRow(detail.getProductName(), toPlainStr(detail.getUnitPrice().toPlainString()), number, toPlainStr(detail.getPayAmount().toPlainString())
, 18, 0, 5, 6);
String row = getRow(detail.getProductName(), toPlainStr(detail.getUnitPrice().stripTrailingZeros().toPlainString()), number, toPlainStr(detail.getPayAmount().toPlainString())
, 18, 0, 5, 5);
data.append(row);
if (StrUtil.isNotBlank(detail.getSkuName())) {
data.append(getFormatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s))
@@ -280,14 +300,16 @@ public interface PrinterImpl {
}
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))
.append(signLabelInfo.br);
data.append(getFormatLabel(StrUtil.format("原价: {}", toPlainStr(printInfoDTO.getOriginalAmount())), signLabelInfo.s))
.append(signLabelInfo.br);
data.append(getFormatLabel("原价:", signLabelInfo.s));
data.append(getFormatLabel(toPlainStr(printInfoDTO.getOriginalAmount()), signLabelInfo.Right, signLabelInfo.s));
data.append(signLabelInfo.br);
if (ObjectUtil.isNotNull(printInfoDTO.getDiscountAmount())) {
data.append(getFormatLabel(StrUtil.format("优惠金额: -{}", toPlainStr(printInfoDTO.getDiscountAmount())), signLabelInfo.s))
.append(signLabelInfo.br);
}
if (StrUtil.isNotBlank(printInfoDTO.getRemark())) {
data.append(getFormatLabel(StrUtil.format("备注:{}", printInfoDTO.getRemark()), signLabelInfo.l, signLabelInfo.bold)).append(signLabelInfo.br);
data.append(getFormatLabel(StrUtil.format("备注:{}", printInfoDTO.getRemark()), signLabelInfo.s)).append(signLabelInfo.br);
}
data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br);
data.append(getFormatLabel(StrUtil.format("应付金额: {}", printInfoDTO.getPayAmount()), signLabelInfo.s, signLabelInfo.bold)).append(signLabelInfo.br);

View File

@@ -58,7 +58,11 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl {
.setQr(new String[]{"<QR>", "</QR>"})
.setCenter(new String[]{"<C>", "</C>"})
.setCenterBold(new String[]{"<CB>", "</CB>"})
.setRight(new String[]{"<RIGHT>", "</RIGHT>"})
.setRs("RS")
.setBr("<BR>")
.setCut("")
.setBold(new String[]{"<B>", "</B>"});
@Override