Printing on "Bixolon Thermal Printer" using JAVA, "No pages found!" error

1.7k views Asked by At

I have been trying to use a thermal-printer "Bixolon SRP-F310" and print some text using JAVA's PrintService. Printer is detected and there is no exception while calling the print function. I can see in the web interface of Cups that the print event is called. However the printer doesn't print and the error message "No pages found!" can be seen in the web-interface of Cups. Any help will be appreciated. I have included the screenshot of the Cups web-interface and the error logs.

import javax.print.*;
import java.util.Arrays;
import java.util.List;

public class Printer {
    static Printer INSTANCE;

    public static void main(String[] args) {
        INSTANCE = new Printer();

        List<PrintService> services = INSTANCE.getServicesByName("BIXOLON_SRP-F310");
        if(services == null) {
            throw new RuntimeException("No printer services available");
        }
        INSTANCE.printServices(services);

        try {
            INSTANCE.print(services.get(0), "Hello");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public List<PrintService> getServicesByName(String serviceName) {
        //Find printer service by name
        AttributeSet aset = new HashAttributeSet();
        aset.add(new PrinterName(serviceName, null));
        return Arrays.asList(PrintServiceLookup.lookupPrintServices(null, aset));
    }

    public void print(PrintService service, String printData) throws Exception {
        if(service == null) {
            throw new Exception("Service is not valid");
        }
        if(printData == null) {
            throw new Exception("Nothing to print");
        }

        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        pras.add(new Copies(1));
        pras.add(new PrinterResolution(180,180,PrinterResolution.DPI));

        DocPrintJob job = service.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);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void printServices(List<PrintService> services) {
        System.out.println("Printer Services found:");
        for (PrintService service : services) {
            System.out.println("\t" + service);
        }
    }
}

Web Interface of Cups:

Web Interface of Cups showing the printing job added, but with the error "No pages found!"

Error Logs:

http://pastebin.com/kYiKGsSn

2

There are 2 answers

1
Naresh Sharma On

Do the following steps and Hopefully your problem will be solved.

  1. Check the IP of your printer if it's same which you are hitting through CUPs then fine otherwise you have to reset the IP.
  2. Reset IP: Press the feed button of your thermal printer for 2-3 min a long print receipt will print with detail info about the printer.

Now just attache your printer with LAN cable to your PC and open the printer settings. Here you can reset the printer IP according to the manual of that particulate printer.

After setting the IP now try again from the server to hit on that thermal printer with new IP. If your CUPS is installed properly then it will work and otherwise you have to check the CUPS.

Check all these things and let me know is that works or any error message.

1
anwar On

I'm facing the very same problem as you did. You may try to setup your page size and format. Try to do that.

You can as well do a simple troubleshoot such as using another printer. If things goes OK, it is safe to assume that there's nothing wrong with your code, but the printer driver you are currently using might be causing the problem.