我需要爲我的打印例程實現一個偵聽器,以便從打印機獲取狀態。我正在使用PrinterJob,但偵聽器PrintServiceAttributeListener對我來說是不夠的。我想實現DocPrintJob的監聽器。我如何轉換到DocPrintJob?PrinterJob與DocPrintJob
這裏是我的原代碼:
public void print(int bufWidth, int bufHeight, BufferedImage bufImage, String printerName, String doPrint)
{
try
{
image = bufImage;
if (doPrint.toUpperCase().equals("YES"))
{
PrinterJob printerJob = getPrinterJob(printerName);
PrintService printService = printerJob.getPrintService();
//printService.addPrintServiceAttributeListener(this);
//printerJob.addPrintJobListener(new PrintJobMonitor());
int width = bufImage.getWidth();
int height = bufImage.getHeight();
PageFormat pf = printerJob.defaultPage();
Paper paper = pf.getPaper();
paper.setSize(width, height);
double imageableX = fromCMToPPI(0.1);
double imageableY = fromCMToPPI(0.1);
double imageableWidth = width - fromCMToPPI(0.1);
double imageableHeight = height - fromCMToPPI(0.1);
paper.setImageableArea(imageableX, imageableY, imageableWidth, imageableHeight);
pf.setOrientation(PageFormat.LANDSCAPE);
pf.setPaper(paper);
PageFormat validatePage = printerJob.validatePage(pf);
printerJob.setPrintable(new MyPrintable(), validatePage);
printerJob.print();
}
}
catch (Exception ex)
{
}
}
如果您添加相應的編程語言標記(Java?),這將有所幫助。 – Filburt
您是否找到解決方案? – whizzzkey
嗨@whizzzkey。不,但是由於打印機有一個SNMP接口,我用它來代替。 –