1
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 java program that does this.
The program runs perfect, generated a jar, pasted along with the php files inside WAMP www, when I open cmd, navigate to this folder and run the following...
java -jar crachaPrinter.jar imagem.png
The java program runs perfectly and sends to print, everything happens right...
But when I put in my php script the following line...
exec("java -jar crachaPrinter.jar imagem.png");
The java program 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)
A request, excerpt from the code where the error is called:
try {
printJob.print();
} catch (PrinterException ex) {
Logger.getLogger(CrachaPrinter.class.getName()).log(Level.SEVERE, null, ex);
}
I don’t understand why the same file. jar finds a print service when executed directly in cmd and not when calling the function by PHP exec, which can be done?
I need that when the page generates the image, it calls this script to automatically send for printing, that’s the way I found since PHP doesn’t do it natively currently, I’ve already used exec() to run programs like this, but I’ve never had this kind of trouble.
what’s on line 49 of Crachaprinter.java?
– Math
It is the Try that executes the function to execute the Pronterjob
– evandrobm
could edit your question by adding this snippet of Try code?
– Math
When you open the CMD, you run the jar as an OS user. Is apache running with that same user? Checked if this could be an OS access permissions issue?
– humungs
@Ricardogiaviti I have not checked anything in this regard, I will take a look at what I can get out of it and I will give back. I need to make this work for yesterday haha :(
– evandrobm
Which OS are you using? Is the goal to print to a printer connected to the server or client? What type of printer (USB, Parallel, Serial, uses native driver, or needs a legacy driver)? I have written several applications making PHP+Printer folding and each scenario has its details... answer these questions, maybe I can help.
– Vieira
Friend, you could put the java code of the print?
– EA.Jsp.Android
Bah Master, I haven’t had this code in a long time, sorry.
– evandrobm