为什么使用相同的页码多次调用java Printable的print方法? [英] Why does the java Printable's print method get called multiple times with the same page number?

查看:506
本文介绍了为什么使用相同的页码多次调用java Printable的print方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 sun的文档

打印系统可能会要求在移动到下一页之前多次呈现页面。

"The printing system might request that a page be rendered multiple times before moving to the next page."

示例总是显示如下:

Printable print(Graphics g, PageFormat pageFormat, int page) {
    if (page == 0)
      do...
    else if(page == blah...)
}

如果您遵循这种模式,您的代码通常可以正常工作,因为它是基于页码显式的。不遵循这种模式给我带来了巨大的痛苦,直到我意识到它被多次调用相同的页码并开始缓存页面。

If you follow this pattern your code typically works fine because it is explicit based on the page number. Not following this pattern caused me great pain until I realized it was getting called multiple times with the same page number and started to cache the pages.

为什么使用相同的页码多次调用java Printable的print方法?

Why does the java Printable's print method get called multiple times with the same page number?

推荐答案

Java打印系统受底层OS打印系统的支配,该系统可能会要求多次呈现单个页面。

The Java printing system is at the mercy of the underlying OS printing system, and that system may request a single page be rendered multiple times.

一个原因是带状打印 - 如果打印机没有足够的内存来一次呈现整个页面 - 在这种情况下,操作系统会再次向Java请求页面以便它可以打印带状页面(带)。这是Java 2D程序员指南中打印概念

One reason is banded printing -- if the printer doesn't have enough memory to render the entire page at once -- in that case, the OS will ask Java for the page again so it can print the page in strips ("bands"). This is the specific case mentioned in the Java 2D Programmer's Guide, in the section "Printing Concepts".

可能还有其他原因;这完全取决于操作系统的打印系统。

There may be other reasons; it's really up to the OS's printing system.

这篇关于为什么使用相同的页码多次调用java Printable的print方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆