I am working on a project developing a kiosk web app, the project is a demo of kiosk devices, so i need to send to print a receipt when user clicks a button. I made a java jar that already print the receipt but when it is called from php exec('print.jar', $output) PrintServiceLookup.lookupDefaultPrintService() throws nullpointerexception. I have tried also with system() and shell_exec() and so on.
I hope somebody can help cause I have looking for days.
This is the jar code
public class PrintText {
public static void main(String[] args) throws PrintException, IOException {
String defaultPrinter = PrintServiceLookup.lookupDefaultPrintService().getName();
System.out.println("Default printer: " + defaultPrinter);
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
PrinterOptions p=new PrinterOptions();
p.resetAll();
p.initialize();
p.feedBack((byte)2);
p.color(0);
p.alignCenter();
p.setText("PANTALLAS LINCE");
p.newLine();
p.setText("MUPI INTERACTIVO");
p.newLine();
p.addLineSeperator();
p.newLine();
p.alignCenter();
p.setText("Tu Cuenta");
p.newLine();
p.addLineSeperator();
p.newLine();
p.alignLeft();
p.setText("Folio No : 2001 Venta directa : E511");
p.newLine();
p.setText("Fecha : " + "01/01/1801 22:59");
p.newLine();
p.setText("Metodo de Pago : Tarjeta");
p.newLine();
p.setText("Suc : Altabrisa Mérida");
p.newLine();
p.addLineSeperator();
p.newLine();
p.alignCenter();
p.setText(" - -Recibo de Compra - ");
p.newLine();
p.alignLeft();
p.addLineSeperator();
p.newLine();
p.setText("Id DescPrecioQty");
p.newLine();
p.addLineSeperator();
p.newLine();
p.setText("1" + "" + "Aliens Everywhere" + "" + "100" + "" + "5"); p.newLine();
p.setText("1" + "" + "Aliens Everywhere" + "" + "100" + "" + "5"); p.newLine();
p.setText("1" + "" + "Aliens Everywhere" + "" + "100" + "" + "5"); p.newLine();
p.setText("1" + "" + "Aliens Everywhere" + "" + "100" + "" + "5"); p.newLine();
p.setText("1" + "" + "Aliens Everywhere" + "" + "100" + "" + "5"); p.newLine();
p.setText("1" + "" + "Aliens Everywhere" + "" + "100" + "" + "5"); p.newLine();
p.addLineSeperator();
p.feed((byte)3);
p.finit();
p.feed((byte)15);
// InputStream is = new ByteArrayInputStream(Header.getBytes("UTF8"));
InputStream is = new ByteArrayInputStream(p.finalCommandSet().getBytes());
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc doc = new SimpleDoc(is, flavor, null);
DocPrintJob job = service.createPrintJob();
PrintJobWatcher pjw = new PrintJobWatcher(job);
job.print(doc, pras);
pjw.waitForDone();
is.close();
}
}
this is php
$output = exec('print.jar 2>&1');
var_dump($output);
the problem is that PrintServiceLookup.lookupDefaultPrintService() throws null when run with php exec() but works ok if it is called from windows explorer double clicking
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…