これは、PDFファイルを印刷し、印刷中にイベントを取得するための私のコードです。私の問題は、それが常に に行き、printJobNoMoreEvents
に入らないことprintJobCompleted
です。問題は何でしょうか?どうすればこれを修正できますか?printJobNoMoreEvents
イベント内からジョブが完了したかどうかを確認することはできますか?
これは私のコードです:
import com.qoppa.pdfPrint.PDFPrint;
import java.awt.print.PrinterJob;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.SimpleDoc;
import javax.print.event.PrintJobEvent;
import javax.print.event.PrintJobListener;
public class PdfPrint implements PrintJobListener{
public static void main(String[] args) {
try
{
// Create a printer job and get its PrintService
PrinterJob pJob = PrinterJob.getPrinterJob();
PrintService ps = pJob.getPrintService();
// Load the PDF document and create SimpleDoc from it
PDFPrint pdfPrint = new PDFPrint("C:\\temp\\file printing 1.pdf", null);
SimpleDoc printDoc = new SimpleDoc(pdfPrint, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);
// Get a doc print job from the service and set the listener and Printable
DocPrintJob docPrint = ps.createPrintJob();
docPrint.addPrintJobListener(new PdfPrint());
docPrint.print(printDoc, null);
}
catch (Exception ex)
{
Logger.getLogger(PdfPrint.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void printDataTransferCompleted(PrintJobEvent pje) {
System.out.println("printDataTransferCompleted");
}
@Override
public void printJobCompleted(PrintJobEvent pje) {
System.out.println("printJobCompleted");
}
@Override
public void printJobFailed(PrintJobEvent pje) {
System.out.println("printJobFailed");
}
@Override
public void printJobCanceled(PrintJobEvent pje) {
System.out.println("printJobCanceled");
}
@Override
public void printJobNoMoreEvents(PrintJobEvent pje) {
System.out.println("printJobNoMoreEvents");
}
@Override
public void printJobRequiresAttention(PrintJobEvent pje) {
System.out.println("printJobRequiresAttention");
}
}
タクンの事前。