| TextPrinter 1.3
Sample Code |
![]() |
WILDCREST ASSOCIATES |
PrintTextFile is a sample Java application showing the use of TextPrinter to print text files.
PrintTextFile has a File menu which allows you to Open any text file and to Print the currently open file. It also has a Page Setup command which brings up a dialog box that allows you to change all the page formatting parameters supported by TextPrinter. PrintTextFile also has Font, Style, and Size menus to control the display and printing font. A sample file TextPrinterTest.txt is also provided in the same folder and illustrates some of the edge cases supported by TextPrinter.
The PrintTextFileTestApplication folder contains all the classes PrintTextFile needs to run. To run PrintTextFile under Windows, you can simply double-click the file:
PrintTextFile.bat
Alternatively, you can launch an MS-DOS window, change the current directory to the folder PrintTextFileTestApplication within the TextPrinter folder, then type:
java PrintTextFile
or on some systems you may need to use:
java -classpath .;%classpath% PrintTextFile
NOTE: If you are using JDK 1.2 or JDK 1.2.1, there is a bug in the Java 2D font system that prevents the printing of text (see Installation & Compatibility section for details). When running PrintTextFile under JDK 1.2 or JDK 1.2.1, you need to add the switch -Djava2d.font.usePlatformFont=true to your command line, e.g.:
java -Djava2d.font.usePlatformFont=true
PrintTextFile
or
java -classpath .;%classpath% -Djava2d.font.usePlatformFont=true
PrintTextFile
The source code for PrintTextFile is also provided with this distribution. It consists of three files: PrintTextFile.java, PageSetupDialog.java (improved over previous releases), and AboutDialog.java. You may use, modify, and distribute this code without restriction in developing any application that uses TextPrinter (see License information). Most of this code was automatically generated by Symantec Visual Cafe and, while somewhat verbose, is straightforward with the parts relevant to using TextPrinter not hard to find.
NOTE: Printing has undergone a long series of modifications and bug fixes from the early JDK 1.1.x release through the JDK 1.2 betas, many of these resulting in changes to page dimensions and resolution values for different JDK's and OS's.. TextPrinter has tracked these changes for each new release, but writing a single program that can print correctly regardless of the underlying JDK and OS has been difficult. PrintTextFile 1.3 now includes the source code for a method "defaultMargin" that will automatically configure TextPrinter correctly for Windows JDK's 1.1.4, 1.1.5, 1.1.5, 1.1.7, 1.2, and 1.2.1, SunOS and Solaris JDK's 1.1.x and 1.2, and Macintosh JDK 1.1.x. PrintTextFile shows how a single program can produce correctly printed output across this range of Java platforms and OS's.
NOTE: A bug in the Windows 95 Java implementation limits the number of characters in a Java TextArea to 32K, so very long text files may be truncated when read into PrintTextFile and, as a consequence, when printed by TextPrinter. TextPrinter itself does not have this limitation and can print text of any length.