I have little experience with Java's Printer Api. Now I'm working on a java entrprise application that is hosted on a linux Server and this application print some documents, actually I'm using
javax.print
package to manage this situation. This is the code that I'm using to print:
FileInputStream in = new FileInputStream(fileToPrint);
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
Doc doc = new SimpleDoc(in, flavor, null);
DocPrintJob job = myService.getPrintService().createPrintJob();
PrintJobWatcher pjw = new PrintJobWatcher(job,daProcessare);
job.print(doc, pras);
pjw.waitForDone();
in.close();
public PrintJobWatcher(DocPrintJob job,FatturaCodaInvio fileToProcess) {
job.addPrintJobListener(new PrintJobAdapter() {
public void printJobCanceled(PrintJobEvent pje) {
System.out.println("Print Canceled");
allDone(false,"Print Canceled");
}
public void printJobCompleted(PrintJobEvent pje) {
System.out.println("Print Completed");
allDone(true,"Print Completed");
}
public void printJobFailed(PrintJobEvent pje) {
System.out.println("Print failed");
allDone(false,"Print failed");
}
public void printJobNoMoreEvents(PrintJobEvent pje) {
System.out.println("Print No More Events");
allDone(true,"Print No More Events");
}
void allDone(boolean esito, String info) {
synchronized (PrintJobWatcher.this) {
System.out.println("Printing done ...");
PrintJobWatcher.this.notify();
}
}
});
}
Now in some situation I have little control on my printer. For example I'm unable to undertand If my printer in not ready or if it has some problem, then I would want to check the status of mi printer before to send my documents. To do this I'm Googling and I found some libraries lie cups4j that maybe could help me. Is there someone who has encountered this same problem? Can you give me some suggestion about this?