I have a java application to print and auto cut the receipt using a thermal printer (Bixolon srp 350 plus)

Initially I was having problem with auto cutting the receipt but after many trials and google search, I somehow manage to auto cut the receipt. But the problem is that when I deploy the war application in my test machine, it prints fine but it is not cutting the paper at the end. I even deployed the war file into my development machine's tomcat and it is auto cutting fine.

Both the development machine and the test machine are using windows 7 - ultimate , the same apache-tomcat-6.0.18 , and JDK6/JRE6 .

Initially the Test machine had jre6 installed and after auto cutting was unsuccessful . I installed jdk6 which i was using in my development machine to no success.

The two machines are of different brands with different hardware configuration. Can anyone please help me out on this? Is this something to do with the previous JRE6 installed and was not properly removed from windows registry?

I am using grails 1.3.7 along with mysql 5.5.

My code is below :

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();
    }


}

If anyone can help me out with a better way to implement the auto cutting functionality it would be a great help.

1

There are 1 answers

4
dave yendrembam On BEST ANSWER

I was able to resolve the auto cutting issue by setting the bixolon srp 350 plus printer as the default printer in the windows 7 printer setting page. Still its a bit weird. If anyone can help me with a better way to implement auto cutting functionality , it will still be a great help. Cheers!