1

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

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

杯子的网页界面:

Cups 的 Web 界面显示已添加的打印作业,但出现错误

错误日志:

http://pastebin.com/kYiKGsSn

4

2 回答 2

1

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

  1. 检查打印机的 IP,如果它与您通过 CUP 击中的 IP 相同,那么就可以了,否则您必须重置 IP。
  2. 重置 IP:按下热敏打印机的进纸按钮 2-3 分钟,将打印一份长打印收据,其中包含有关打印机的详细信息。

现在只需将您的打印机用 LAN 电缆连接到您的 PC 并打开打印机设置。在这里您可以根据该颗粒打印机的手册重置打印机IP。

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

检查所有这些事情,让我知道是否有效或任何错误消息。

于 2014-12-29T14:15:52.390 回答
0

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

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

于 2015-01-15T09:47:34.577 回答