gpt4 book ai didi

java - 尝试在热敏打印机(Bixolon SRP350 plus)的 JAVA 应用程序中实现自动切割功能时出现奇怪的行为

转载 作者:行者123 更新时间:2023-12-01 05:13:24 25 4
gpt4 key购买 nike

我有一个 java 应用程序,可以使用热敏打印机(Bixolon srp 350 plus)打印和自动剪切收据

最初,我在自动剪切收据时遇到问题,但经过多次试验和谷歌搜索,我以某种方式设法自动剪切收据。但问题是,当我在测试机中部署 war 应用程序时,它打印得很好,但最后没有切割纸张。我什至将 war 文件部署到我的开发机器的 tomcat 中,并且它可以自动切割。

开发机和测试机均使用windows 7-ultimate,同样的apache-tomcat-6.0.18,JDK6/JRE6。

最初测试机安装了jre6,之后自动切割不成功。我安装了我在开发机器上使用的jdk6,但没有成功。

两台机器为不同品牌,硬件配置不同。有人可以帮我解决这个问题吗?这是否与之前安装的 JRE6 且未从 Windows 注册表中正确删除有关?

我正在使用 grails 1.3.7 和 mysql 5.5。

我的代码如下:

public void printBill(String printData) throws Exception {
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(5));
pras.add(new PrinterResolution(180,180,PrinterResolution.DPI));


PrintService pss[] = PrintServiceLookup.lookupPrintServices(null,pras);
if (pss.length == 0) {
throw new RuntimeException("No printer services available.");
}

if(printData == null) {
throw new Exception("nothing to print");
}

PrintService ps = pss[0];

DocPrintJob job = ps.createPrintJob();
DocAttributeSet das = new HashDocAttributeSet();
das.add(new PrinterResolution(180,180,PrinterResolution.DPI));

byte[] desc = printData.getBytes();
Doc doc = new SimpleDoc(desc, DocFlavor.BYTE_ARRAY.AUTOSENSE, das);

try {
job.print(doc, pras);
cutPaper();
} catch (Exception e) {
e.printStackTrace();
}
}

/*
* TODO improvision to auto cut bill, need to find a proper way to cut
*/
private void cutPaper() throws Exception{
TempPageCutter pageCutter = new RestaurantPrinter().new TempPageCutter();

pageCutter.cutReceipt();

}

private class TempPageCutter implements Printable {

@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
throws PrinterException {
if(pageIndex > 0)
return NO_SUCH_PAGE;

System.out.println("Cutting");
graphics.drawString("", 0, 0);

return PAGE_EXISTS;
}

public void cutReceipt() throws PrinterException {
System.out.println("cutReceipt");
PrintService[] printService = PrinterJob.lookupPrintServices();

if(printService == null || printService.length < 1) {
return;
}
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(this);
job.print();
}


}

如果有人可以帮助我找到更好的方法来实现自动剪切功能,那将是一个很大的帮助。

最佳答案

我能够通过在 Windows 7 打印机设置页面中将 bixolon srp 350 plus 打印机设置为默认打印机来解决自动剪切问题。还是有点奇怪。如果有人可以帮助我提供更好的方法来实现自动切割功能,那仍然是一个很大的帮助。干杯!

关于java - 尝试在热敏打印机(Bixolon SRP350 plus)的 JAVA 应用程序中实现自动切割功能时出现奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11702859/

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