我有一个Java应用程序进行打印,自动切纸使用热敏打印机(BIXOLON SRP 350个加)怪异的行为,而试图在JAVA应用热敏打印机来实现自动切割功能(BIXOLON SRP350加)
收据最初我遇到了自动切割收据的问题,但经过多次试用和谷歌搜索后,我以某种方式设法自动切割收据。但问题是,当我将测试应用程序部署在我的测试机器上时,它的打印效果不错,但最终并未削减纸张。我甚至将war文件部署到我的开发机器的tomcat中,并且它自动切割得很好。
开发机器和测试机器都使用windows 7 - 最终的,相同的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();
}
}
如果有人能帮助我实现自动切纸功能,更好的办法那将是一个很大的帮助。
我从来没有使用过JAVA的Bixolon打印机。你能给我一个头马吗?一个简单的例子,如何打印使用JAVA也许。 – yuva 2014-12-04 08:43:47