我使用以下代碼在Java 1.5中進行打印,但是將打印作業發送到打印機的時間平均爲35-40秒。它花費在以下行上:printJob.print(attrSet);在Java 1.5中打印,速度慢嗎?
有沒有辦法加快速度?
private void print() {
PrintRequestAttributeSet attr;
attr = new HashPrintRequestAttributeSet();
attr.add(OrientationRequested.LANDSCAPE);
MediaSize mediaSize =
MediaSize.getMediaSizeForName(MediaSizeName.NA_LEGAL);
float[] size = mediaSize.getSize(MediaSize.INCH);
attr.add(new MediaPrintableArea(0, 0, size[0], size[1],
MediaPrintableArea.INCH));
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this);
if (printJob.printDialog())
try {
for (Component cmp : componentsToBePrinted) {
this.componentToBePrinted = cmp;
printJob.print(attrSet);
}
} catch(PrinterException pe) {
System.out.println("Error printing: " + pe);
}
}
打印一般很慢。就像使用任何系統資源一樣,這可能是阻塞操作。 – cdeszaq 2012-03-02 16:12:17