您是否檢查過Java Print API?從http://download.oracle.com/javase/1.4.2/docs/api/javax/print/event/PrintJobListener.html:
公共接口
PrintJobListener這個監聽 接口
實現應該被附加到 DocPrintJob的監測 打印機的工作狀態。
我想你可以提交一個打印作業,然後通過它來監視它的狀態。
還有一個相當完整的例子在
exampledepot.com/egs/javax.print/WaitForDone.html:
(注:URL似乎有所改變,並指出潛在的惡意軟件)
try {
// Open the image file
InputStream is = new BufferedInputStream(
new FileInputStream("filename.gif"));
// Create the print job
DocPrintJob job = service.createPrintJob();
Doc doc = new SimpleDoc(is, flavor, null);
// Monitor print job events
PrintJobWatcher pjDone = new PrintJobWatcher(job);
// Print it
job.print(doc, null);
// Wait for the print job to be done
pjDone.waitForDone();
// It is now safe to close the input stream
is.close();
} catch (PrintException e) {
} catch (IOException e) {
}
class PrintJobWatcher {
// true iff it is safe to close the print job's input stream
boolean done = false;
PrintJobWatcher(DocPrintJob job) {
// Add a listener to the print job
job.addPrintJobListener(new PrintJobAdapter() {
public void printJobCanceled(PrintJobEvent pje) {
allDone();
}
public void printJobCompleted(PrintJobEvent pje) {
allDone();
}
public void printJobFailed(PrintJobEvent pje) {
allDone();
}
public void printJobNoMoreEvents(PrintJobEvent pje) {
allDone();
}
void allDone() {
synchronized (PrintJobWatcher.this) {
done = true;
PrintJobWatcher.this.notify();
}
}
});
}
public synchronized void waitForDone() {
try {
while (!done) {
wait();
}
} catch (InterruptedException e) {
}
}
}
感謝我在此基礎上和它似乎工作構建解決方案,將鏈接到代碼時,它不。 exampledepot非常有用 – Gwilym 2010-09-18 19:57:27