The SpooledFileViewer class creates a window for viewing Advanced Function Printing™ (AFP™) and Systems Network Architecture character string (SCS) files that have been spooled for printing. The class essentially adds a "print preview" function to your spooled files, common to most word processing programs, as illustrated in Figure 1.
The spooled file viewer is especially helpful when viewing the accuracy of the layout of the files is more important than printing the files, or when viewing the data is more economical than printing, or when a printer is not available.
Using the SpooledFileViewer class
Three constructor methods are available to create an instance of the SpooledFileViewer class. The SpooledFileViewer() constructor can be used to create a viewer without a spooled file associated with it. If this constructor is used, a spooled file will need to be set later using setSpooledFile(SpooledFile). The SpooledFileViewer(SpooledFile) constructor can be used to create a viewer for the given spooled file, with page one as the initial view. Finally, the SpooledFileViewer(spooledFile, int) constructor can be used to create a viewer for the given spooled file with the specified page as the initial view. No matter which constructor is used, once a viewer is created, a call to load() must be performed in order to actually retrieve the spooled file data.
Then, your program can traverse the individual pages of the spooled file by using the following methods:
If, however, you need to examine particular sections of the document more closely, you can magnify or reduce the image of a page of the document by altering the ratio proportions of each page with the following:
Your program concludes with calling the close() method that closes the input stream and releases any resource associations with the stream.
Using the SpooledFileViewer
An instance of the SpooledFileViewer class is actually a graphical representation of a viewer capable of displaying and navigating through an AFP or SCS spooled file. For example, the following code creates the spooled file viewer in Figure 1 to display a spooled file previously created on the server.
// Assume splf is the spooled file. // Create the spooled file viewer SpooledFileViewer splfv = new SpooledFileViewer(splf, 1); splfv.load(); // Add the spooled file viewer to a frame JFrame frame = new JFrame("My Window"); frame.getContentPane().add(splfv); frame.pack(); frame.show();
The actual size button returns the spooled file page image to its original size by using the actualSize() method.
The fit width button stretches the spooled file page image to the left and right edges of the viewer's frame by using the fitWidth() method.
The fit page button stretches the spooled file page image vertically and horizontally to fit within the spooled file viewer's frame by using the fitPage() method.
The zoom button allows you to increase or decrease the size of the spooled file page image by selecting one of the preset percentages or entering your own percent in a text field that appears in a dialog box after selecting the zoom button.
The go to page button allows you to go to a specific page within the spooled file when selected.
The first page button takes you to the first page of the spooled file when selected and indicates that you are on the first page when deactivated.
The previous page button takes you to the page immediately before the page you are viewing when selected.
The next page button advances you to the page immediately after the page you are viewing when selected.
The last page button advances you to the last page of the spooled file when selected and indicates that you are on the last page when deactivated.
The load flash page button loads the previously viewed page by using the loadFlashPage() method when selected.
The set paper size button allows you to set the paper size when selected.
The set viewing fidelity button allows you to set the viewing fidelity when selected.