package hlsoft;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.util.ArrayList;
import java.util.List;
import hlsoft.PrintModel;
/**
* 通用热敏打印机类
*/
public class Prient implements Printable {
/**
* 打印内容主题
*/
private List<PrintModel> listModel;
/**
* 小票标题
*/
private String title;
/**
* 打印纸高度
*/
private Integer height;
/**
* 标题距左距离
*/
private Integer marginLeft = 50;
/**
* 标题距上距离
*/
private Integer marginTop = 10;
public int commonPrint() {
int height = 0 + listModel.size() * 20 + this.height;
// 通俗理解就是书、文档
Book book = new Book();
// 打印格式
PageFormat pf = new PageFormat();
pf.setOrientation(PageFormat.PORTRAIT);
// 通过Paper设置页面的空白边距和可打印区域。必须与实际打印纸张大小相符。
Paper p = new Paper();
p.setSize(113, 85);
p.setImageableArea(2, 2, 113, 85);
pf.setPaper(p);
// 把 PageFormat 和 Printable 添加到书中,组成一个页面
book.append(new Prient(this.listModel, this.title), pf);
// 获取打印服务对象
PrinterJob job = PrinterJob.getPrinterJob();
job.setPageable(book);
try {
job.print();
} catch (PrinterException e) {
System.out.println("================打印出现异常");
}
return 0;
}
@Override
public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
if (page > 0) {
return NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D) g;
/*g2d.setFont(new Font(title, Font.PLAIN, 12));
g2d.drawString(title, marginLeft, marginTop);*/
g2d.setFont(new Font(title, Font.PLAIN, 8));
int i = 1;
//g2d.drawString("--------------------------------------------", 7, 20);
for (PrintModel m : listModel) {
/*if (!m.getIsWrap()) {
if (m.getName()!=null&&!"".equals(m.getName())) {
g2d.drawString(m.getName() + m.getVal(), 7, 30 + i * 12);
System.out.println(i);
} else if (null != m.getImage()) {
g2d.drawImage(m.getImage(), 7, 7 + i * 12, null);
//i += 8;
System.out.println(i);
}
} else {
g2d.drawString(m.getName(), 7, 30 + i * 12);
i++;
g2d.drawString(m.getVal(), 7, 30 + i * 12);
}
i++;*/
if (m.getName()!=null&&!"".equals(m.getName())) {
g2d.drawString(m.getName() + m.getVal(), m.getX(), m.getY());
} else if (null != m.getImage()) {
g2d.drawImage(m.getImage(), m.getX(), m.getY(), null);
}
}
return PAGE_EXISTS;
}
public static void main(String[] args) {
List<PrintModel> oo = new ArrayList<PrintModel>();
oo.add(new PrintModel("编号1", "0055726"));
try {
oo.add(new PrintModel(new QRCodeEvents().writeQrCodeContent("text", "D:/")));
} catch (Exception e1) {
}
Prient p = new Prient(oo, "运输单", 340);
p.commonPrint();
}
public Prient(List<PrintModel> listModel, String title, Integer height, Integer marginLeft, Integer marginTop) {
this.listModel = listModel;
this.title = title;
this.height = height;
this.marginLeft = marginLeft;
this.marginTop = marginTop;
}
public Prient(List<PrintModel> listModel, String title, Integer height) {
this.listModel = listModel;
this.title = title;
this.height = height;
}
public Prient(List<PrintModel> listModel, String title) {
this.listModel = listModel;
this.title = title;
}
}
热敏打印机demo(含demo和jar包)



热敏打印机技术是一种广泛应用于零售、餐饮、物流等行业的打印技术。它主要依赖于热敏纸,这种纸在受热时会发生化学反应,从而形成可见的打印文本和图像。相较于传统的针式打印机,热敏打印机具有打印速度快、噪音低、维护简单等优点。 在给定的"热敏打印机demo(含demo和jar包)"中,我们可以推测这是一个用于演示如何与热敏打印机进行交互的程序。通常,这样的demo会包含一些基础的API调用示例,帮助开发者了解如何设置打印机参数、发送打印指令以及处理打印任务。同时,提供的jar包则可能包含了实现这些功能的类库,供开发者在自己的项目中引用和使用。 让我们关注“将打印机设置为默认”这一操作。在热敏打印机的使用中,设置默认打印机是必不可少的步骤,这样系统才能知道应该通过哪个设备进行打印。这通常涉及到操作系统级别的配置,开发者可能需要调用特定的API来完成这一过程,例如在Windows系统中使用`PrintUIEntry.exe`命令行工具,或者在Java中使用`PrinterJob`类的`setPrinterJob`方法。 接下来,"测试可打印的话"意味着这个demo可能包括了打印测试页的功能。测试页通常包含各种字符、图形和条形码,用来验证打印机的性能和设置是否正确。开发者可以通过调用打印函数,发送一个预定义的测试页面数据流到打印机,然后观察打印结果。 在"连上打印机就可以直接打印"这句话里,我们可以理解为该demo实现了即插即用的特性。这意味着一旦打印机连接到计算机,无需额外的配置,demo就能自动识别并开始打印。这通常涉及到设备驱动程序的自动化安装和发现机制,对于Java开发者,可以使用Java的`java.awt.print`包来处理这些任务。 在压缩包内的"print"文件,很可能包含了实现以上功能的源代码、资源文件或者是编译后的class文件。如果它是源代码,那么开发者可以直接阅读和学习;如果是编译后的class文件,可能需要反编译查看其内部逻辑。此外,这些文件可能还包含了具体的打印指令格式,例如ESC/POS指令集,这是热敏打印机常用的二进制指令语言,用于控制打印头的动作和打印内容。 这个热敏打印机demo和jar包提供了一个了解和使用热敏打印机的起点,涵盖了设备配置、打印测试和即插即用等功能。通过学习和使用这个demo,开发者能够快速掌握热敏打印机的编程技巧,并将其应用到自己的应用程序中,提高打印效率和服务质量。







































- 1

- #完美解决问题
- #运行顺畅
- #内容详尽
- #全网独家
- #注释完整
- 钢铁的群狼2018-10-22运行不起来…………感觉不太好使

- 粉丝: 1
- 资源: 5
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 基于Java语言的CMS看点资讯项目设计源码
- 基于Springboot+Mybatis框架的JavaWeb员工管理系统后端设计源码
- 基于C++和C语言的文件软硬件加解密平台设计源码
- gf-golang资源
- liqin-songs-春节主题资源
- DeepSeek经验分享-DeepSeek资源
- 活动发布管理-活动资源
- QL6502-汇编语言资源
- 基于C语言的串口助手硬件资料设计源码
- 基于Scala与前端技术栈的空气质量分析与可视化系统设计源码
- 基于Vue3+Electron的医师电子化注册信息系统单机版设计源码
- 基于蒙特卡洛模拟与启发式同步回带削减的MATLAB实现:风光氢负荷场景生成与高效缩减,MATLAB下的风光氢场景生成与启发式同步回带削减法研究,MATLAB代码:风光氢的场景生成与缩减 关键词:风电
- 基于24小时容量利用系数法的线损分摊方法及其通用程序应用:matlab与python版解读与应用实例 ,基于24小时容量利用系数法的线损分摊程序:通用解决方案与Matlab及Python实现,24容量
- 基于C++语言的跨平台Frame框架设计源码
- COMSOL 5.6版超声仿真:检测焊缝缺陷模型专版应用,版本兼容性说明及优化升级解析,COMSOL 5.6超声仿真检测焊缝缺陷新功能解析,COMSOL超声仿真:检测焊缝缺陷 版本为5.6,低于5.6
- 小程序商城源码-Java-C语言资源


