Sample code written in java and kotlin using my ipp-client library.
Use jmDNS to discover printers via Bonjour including AirPrint compatible printers.
val jmDns = JmDNS.create()
jmDns.list("_ipp._tcp.local.").forEach {
val printerName = it.name
val printerUri = with(it) { URI.create("ipp://$server:$port/${getPropertyString("rp")}") }
val ippPrinter = IppPrinter(printerUri)
println("* $printerName")
println(" $printerUri")
println(" $ippPrinter")
}
jmDns.close()
Print a pdf file and wait for the printer to finish.
// initialize printer connection and show printer attributes
IppPrinter ippPrinter=new IppPrinter("ipp://colorjet.local/ipp/printer");
ippPrinter.logDetails();
// print file
File file=new File("my-document.pdf");
IppJob job=ippPrinter.printJob(
file,
documentFormat("application/pdf"),
jobName(file.getName()),
IppColorMode.Monochrome
);
job.logDetails();
// wait until printer has completed the job
job.waitForTermination();
job.logDetails();
implementation("de.gmuth:ipp-client:2.3")