【问题标题】:Printing on "Bixolon Thermal Printer" using JAVA, "No pages found!" error使用 JAVA 在“Bixolon 热敏打印机”上打印,“未找到页面!”错误
【发布时间】:2015-02-02 07:35:07
【问题描述】:

我一直在尝试使用热敏打印机“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);
        }
    }
}

杯子的网页界面:

错误日志:

http://pastebin.com/kYiKGsSn

【问题讨论】:

  • 您是否配置了打印机。就像重置它的 IP 地址一样,因为在该 IP 上,您必须通过 CUP 传递数据。
  • 是的,我已经这样做了,没有运气。

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


【解决方案1】:

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

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

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

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

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

【讨论】:

  • 当我尝试通过 CUPS Web 界面打印时,打印机工作正常。这必须说明IP设置正确。当我尝试通过我的 JAVA 程序打印时,我可以看到发出了打印命令,但打印机没有打印。我已经在问题中解释了我的问题。
【解决方案2】:

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

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

【讨论】:

  • 您的问题解决了吗?我正在尝试另一种方式的 JPOS 驱动程序,但也没有运气。
猜你喜欢
  • 2014-02-02
  • 1970-01-01
  • 2012-10-05
  • 1970-01-01
  • 2013-07-04
  • 2013-03-16
  • 1970-01-01
  • 2019-12-06
相关资源
最近更新 更多