我正在为我们的应用程序开发自定义打印模块。在Windows 7下使用以下代码进行打印效果很好。当我有8页tiff文件时,它产生12MB的线轴。但是当我在Windows XP上执行此代码时,它会生成大小约为300MB的假脱机,并且打印需要很长时间。
请有人告诉我如何加快速度,或者是否有一些解决方法?
感谢
public class TIFFPrintPage implements Printable {
private static final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SSS");
private RenderedImage page;
public TIFFPrintPage(RenderedImage page) {
this.page = page;
}
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
if (page != null) {
// convert to a BufferedImage since I cannot write a RenderedImage for some reason
BufferedImage good = new BufferedImage(page.getWidth(), page.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2dtemp = (Graphics2D) smaller.getGraphics();
g2dtemp.drawRenderedImage(page, new AffineTransform());
Graphics2D g2d = (Graphics2D) graphics;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
g2d.drawImage(smaller, 0, 0, smaller.getWidth(), smaller.getHeight(), null);
g2d.dispose();
good.flush();
return Printable.PAGE_EXISTS;
} else {
return Printable.NO_SUCH_PAGE;
}
}
public static void main(String[] args) throws IOException, PrinterException {
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
PrinterJob printerJob = PrinterJob.getPrinterJob();
printerJob.setPrintService(service);
PageFormat pf = PrinterJob.getPrinterJob().defaultPage();
Paper paper = new Paper();
paper.setSize(595.275591, 841.889764); // width, height A4 format
paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight());
pf.setPaper(paper);
SeekableStream s = new FileSeekableStream("c:/test3.tiff");
TIFFDecodeParam param = null;
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, param);
Book book = new Book();
for (int i = 0; i < dec.getNumPages(); i++) {
book.append(new TIFFPrintPage(dec.decodeAsRenderedImage(i)), pf);
}
printerJob.setPageable(book);
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(Sides.DUPLEX);
printerJob.print(pras);
}
}