使用JAVA在“Bixolon热敏打印机”上打印,“找不到页面!”错误

时间:2014-12-04 12:08:28

标签: java printing thermal-printer cups bixolon-printer

我一直在尝试使用热敏打印机" Bixolon SRP-F310"并使用JAVA的PrintService打印一些文本。检测到打印机,调用打印功能时没有异常。我可以在Cups的Web界面中看到打印事件被调用。但是打印机没有打印并且错误消息"没有找到页面!"可以在Cups的网络界面中看到。任何帮助将不胜感激。我已经包含了Cups web界面的屏幕截图和错误日志。

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 showing the printing job added, but with the error "No pages found!"

错误日志:

http://pastebin.com/kYiKGsSn

2 个答案:

答案 0 :(得分:1)

执行以下步骤,希望您的问题能够得到解决。

  1. 检查您的打印机的IP是否与您通过CUP进行的操作相同,否则您必须重置IP。
  2. 重置IP:按热敏打印机的进纸按钮2-3分钟,将打印一份长打印收据,其中包含有关打印机的详细信息。
  3. 现在只需使用LAN电缆将打印机连接到PC并打开打印机设置即可。您可以在此处根据该微粒打印机的手册重置打印机IP。

    现在设置IP之后,再次从服务器再次尝试使用新IP打开热敏打印机。 如果您的CUPS安装正确,那么它将起作用,否则您必须检查CUPS。

    检查所有这些事情,让我知道这是有效的还是任何错误信息。

答案 1 :(得分:0)

我面临着和你一样的问题。您可以尝试设置页面大小和格式。尽量做到这一点。

您也可以进行简单的故障排除,例如使用其他打印机。如果一切顺利,可以安全地假设您的代码没有任何问题,但您当前使用的打印机驱动程序可能会导致问题。

相关问题