I'm trying to send a PDF to a printer since my microservice-spring5 on Docker.
I found Apache Camel Printer to do this. if you have any others suggestions please comment.
https://camel.apache.org/components/latest/lpr-component.html
So.. I do a telnet to validate that the port 515 is OK for lpd/lpr
I try to send a PDF(InputStream) directly to the printer by lpr
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.
I can't setup a server CUPS in my docker image linux I have to address directly the printer server by code. Any idea ?