1

我正在尝试使用来自 android 的 Cups4j 打印到安装在 linux 机器上的 IPP 打印机。这是代码,我或多或少只是复制了他们在 github 页面上写的内容。

ByteArrayOutputStream os = stvoriRacun(narudzba, djelatnik, brStola);
try {
    CupsClient cupsClient = new CupsClient("192.168.68.180", 631);
    URL printerURL = new URL("http://192.168.68.180:631/printers/bixolonIPP");
    CupsPrinter cupsPrinter = cupsClient.getPrinter(printerURL);
    Map<String, String> attributes = new HashMap<>();
    attributes.put("compression", "none");
    attributes.put("job-attributes", "print-quality:enum:3#fit-to-page:boolean:true#sheet-collate:keyword:collated");

    PrintJob printJob = new PrintJob.Builder(os.toByteArray())
            .jobName("job-name")
            .userName("user-name")
            .copies(2)
            .pageRanges("1-3")
            .duplex(false)
            .portrait(false)
            .color(true)
            .pageFormat("iso-a4")
            .resolution("300dpi")
            .attributes(attributes)
            .build();
}catch (Exception e){
    e.printStackTrace();
}

当我尝试打印时,出现以下错误

07-18 12:26:29.294 30378-30529/com.appid.apps E/AndroidRuntime: FATAL EXCEPTION: Thread-8
                                                              Process: com.appid.apps, PID: 30378
                                                              java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; in class Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; or its superclasses (declaration of 'org.apache.http.conn.ssl.AllowAllHostnameVerifier' appears in /system/framework/framework.jar!classes3.dex)
                                                                  at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
                                                                  at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:966)
                                                                  at org.cups4j.operations.IppOperation.sendRequest(IppOperation.java:176)
                                                                  at org.cups4j.operations.IppOperation.sendRequest(IppOperation.java:131)
                                                                  at org.cups4j.operations.IppOperation.request(IppOperation.java:67)
                                                                  at org.cups4j.operations.cups.CupsGetPrintersOperation.getPrinters(CupsGetPrintersOperation.java:56)
                                                                  at org.cups4j.CupsClient.getPrinters(CupsClient.java:106)
                                                                  at org.cups4j.CupsClient.getPrinter(CupsClient.java:166)
                                                                  at com.appid.apps.IPPPrinter.connect(IPPPrinter.java:107)
                                                                  at com.appid.apps.Printing$1.run(Printing.java:604)
                                                                  at java.lang.Thread.run(Thread.java:764)

或者是否有任何其他库处理来自 android 的 IPP 打印?

4

1 回答 1

0

Cups4j 不支持安卓。您可能会发现添加了对 Android 的支持的分叉。

ipp-client-kotlin从 1.6 版开始支持 Android,应该可以开箱即用。

于 2021-07-14T10:22:55.167 回答