17
Printing
In this chapter:
- PrintGraphics Interface
- PrintJob Class
- Component Methods
- Printing Example
- Printing Arbitrary Content
Java 1.1 introduces the ability to print, a capability that was sadly missing in Java 1.0, even though the Component class had print() and printAll() methods. However, it is possible to print arbitrary content, including multipage documents. The printing facility in Java 1.1 is designed primarily to let a program print its display area or any of the components within its display.
Printing is implemented with the help of one public interface, PrintGraphics, and one public class, PrintJob, of AWT. The real work is hidden behind classes provided with the toolkit for your platform. On Windows NT/95 platforms, these classes are sun.awt.windows.WPrintGraphics and sun.awt.windows.WPrintJob. Other platforms have similarly named classes.
Printing from an applet has security implications and is restricted by the SecurityManager. It is reasonable to suppose that a browser will make it possible to print a page containing an applet; in fact, Netscape has done so ever since Navigator 3.0. However, this ability might not take advantage of Java's printing facility. It isn't reasonable to suppose that an applet will be able to initiate a print job on its own. You might allow a signed applet coming from a trusted source to do so, but you wouldn't want to give any random applet access to your printer. (If you don't understand why, imagine the potential for abuse.) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access