Why call the printing method of Java printable multiple times with the same page number?

From sun's documentation

The printing system may require that the page be rendered multiple times before going to the next page

The example always shows the following:

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

If you follow this pattern, your code usually works because it is explicit based on page numbers It was painful for me not to follow this pattern until I realized that it was called the same page number many times and started caching the page

Why call the printing method of Java printable multiple times with the same page number?

Solution

The Java printing system is pitied by the underlying OS printing system, which may require multiple rendering of a single page

One reason is ribbon printing – if the printer does not have enough memory to render the entire page at once – in which case the operating system will request the page from Java again so that it can print the page ("Ribbon") This is the specific situation mentioned in the "printing concepts" section of the Java 2D programmer's Guide

There may be other reasons; It all depends on the printing system of the operating system

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>