I have a program created in Java that gets a PDF and prints it. To print it use ghostscript:
public static void print(String nomImpresora, String rutaNombreArchivo, int cantVia) throws Exception {
String cmd;
cmd = "gswin64c -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=" + cantVia + " -sDEVICE=mswinpr2 -dNoCancel -sOutputFile=\"\\spool\" + nomImpresora + "\" " + rutaNombreArchivo;
Process p = null;
try {
p = Runtime.getRuntime().exec(cmd);
Log.addLog(Log.tipoMensaje.InfoSis, "Se envio a Imprimir a la impresora: " + Conf.o().getNomImpresora());
Log.addLog(Log.tipoMensaje.InfoSis, "Imprime eFacturaPrint: S, Formato: " + Conf.o().getForamtoImpresion() + ", " + Conf.o().getNumVias() + " vias");
} catch (IOException e) {
Log.addLog(Log.tipoMensaje.ErrorGenerico, "Error al intentar imprimir con gs: " + e.toString());
} finally {
if (p != null) {
p.destroy();
}
}
}
From Netbeans, or running the program from console works perfectly.
What happens is that this program should run in the background at the beginning of the system. So first create a bat that runs the program and set it in the task scheduler. Because the task scheduler does not stop it or start I have investigated that it is best to wrap it, which is why I used JSmooth. I create the service, I install it, it works, with the exception that it does not print. For better of the case I do not capture exceptions.
I tried to send directly to the printer but being a PDF my printer does not interpret it and prints any text.
I appreciate your interest.