自从我在 Docker 上使用 microservice-spring5 以来,我一直在尝试将 PDF 发送到打印机。
我发现 Apache Camel Printer 可以做到这一点。如果您有任何其他建议,请发表评论。
https://camel.apache.org/components/latest/lpr-component.html
所以.. 我做了一个 telnet 来验证端口 515 是否可以用于 lpd/lpr
我尝试通过 lpr 将 PDF(InputStream)直接发送到打印机
public void sendToPrinter(InputStream is) {
String sendTo = "lpr://myIpAddress/myPrinterName?flavor=DocFlavor.INPUT_STREAM&mimeType=PDF";
try {
ModelCamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:start").to(sendTo);
}
});
context.start(); // **exception throw here**
ProducerTemplate template = context.createProducerTemplate();
template.start();
template.send("direct:start", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
byte[] buffer = new byte[is.available()];
int n = is.available();
for (int i = 0; i < n; i++) {
buffer[i] = (byte) is.read();
}
is.close();
exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
Message in = exchange.getIn();
in.setBody(buffer);
}
}
}
Exception: javax.print.PrintException: No printer found with name: myIpAddresse/myPrinterName. Please verify that the host and printer are registered and reachable from this machine.
我无法在我的 docker image linux 中设置服务器 CUPS我必须通过代码直接寻址打印机服务器。任何想法 ?