I have a web application that generates an image for a badge and to be able to send it automatically to print, I created a program in java that does this.
The program runs perfectly, I generated a jar, pasted together with the php files inside the WAMP www, when I open the cmd, I navigate to this folder and execute the following ...
java -jar crachaPrinter.jar imagem.png
The java program runs perfectly and sends it to print, everything happens right ...
But when I put my php script in the following line ...
exec("java -jar crachaPrinter.jar imagem.png");
The program in java returns the following error:
Apr 01, 2014 4:26:27 PM crachaprinter.CrachaPrinter main Grave: null java.awt.print.PrinterException: No print service found. at sun.print.RasterPrinterJob.print (Unknown Source) at sun.print.RasterPrinterJob.print (Unknown Source) at crachaprinter.CrachaPrinter.main (CrachaPrinter.java:49)
On requests, snippet of the code where the error is called:
try {
printJob.print();
} catch (PrinterException ex) {
Logger.getLogger(CrachaPrinter.class.getName()).log(Level.SEVERE, null, ex);
}
I do not understand why the same .jar file encounters a print service when executed directly in cmd and not when I call the function by PHP exec, what can be done?
I need that when the page generates the image, it calls this script to send automatically to print, this was the way I found it since PHP does not do this natively currently, I already used exec () to execute programs in this way, but I've never had this kind of problem.