| TextPrinter 1.0
Installation & Compatibility |
![]() |
WILDCREST ASSOCIATES |
Installation
Download the TextPrinter .zip file and unzip. This will create a TextPrinter folder containing both code and documentation.
To access the documentation, use your favorite browser to view the file TextPrinterREADME.html.
In the main TextPrinter folder you will find the following contents:
1. com\wildcrest folder containing the TextPrinter classes
2. TextPrinter.jar, a jar file containing the same TextPrinter
classes, suitable for installation and use as a JavaBeans component
3. A javadocs folder containing the Javadoc documentation
for the TextPrinter classes
4. A PrintTextFile folder containing the PrintTextFile
sample application jar, source code files, and a test document TextPrinterTestfile.txt
5. PrintTextFile.bat, a Windows batch file that you can
double-click to run PrintTextFile
To use TextPrinter as an ordinary class in Java applications, since
TextPrinter is in package com.wildcrest, the folder com\wildcrest needs
to be accessible from your class path.
You need to do one of the following things:
1. Modify your classpath to include the TextPrinter folder
2. Modify your classpath to include TextPrinter.jar
3. Pick a folder in your current classpath that does not
already have a com folder. Copy the com folder from the TextPrinter folder
into it.
One possibility for this is the folder that
contains your application, which is always in your classpath.
4. Pick an existing com folder in your current classpath
that does not have a wildcrest subfolder. Copy the wildcrest subfolder
from the TextPrinter\com folder into your existing com folder
5.I f you already have a com\wildcrest folder in your
classpath, copy the contents of the TextPrinter\com\wildcrest folder into
it
To use TextPrinter as an ordinary class in Java applets, you need to do one of the following things:
1. Put a com folder containing a wildcrest subfolder containing
the file TextPrinter.class in the same folder as your applet (whether on
your local system or across the
network)
2. In the applet tag, set ARCHIVE="TextPrinter.jar" (or
"C:\directory\TextPrinter.jar" if it is somewhere else)
3. In the applet tag, set CODEBASE="directory-containing-com\wildcrest\TextPrinter.class"
Some regular browsers and appletviewers in other development environments
may honor your system classpath as java does for applications but others
do not. Following the
instructions above for appletviewer should be work for applets in all
cases.
To use TextPrinter as a JavaBean, copy TextPrinter.jar into the jar
folder appropriate for your visual application builder:
for the JavaSoft BDK BeanBox,
copy TextPrinter.jar into the folder <directory-containing-bdk>\bdk\jars
for Symantec Visual Cafe,
you can place TextPrinter.jar anywhere, then use "Insert: Component to
Library..." command, then right click on TextPrinter in the Component
Library view and add to desired palette
for Borland JBuilder, you
can place TextPrinter.jar anywhere, then right click on component palette,
select "Properties", then use "Add from Archive"
for the IBM WebRunner BeanTester,
copy TextPrinter.jar into the folder <directory-containing-webrunnerk>\webrunner\BeanTools\beantester\beans
The TextPrinter.class file in com\wildcrest is identical to the corresponding class file in the TextPrinter.jar archive.
To use the PrintTextFile sample program, click on "Sample Code" link
above and follow the instructions there.
Compatibility
TextPrinter 1.3 was built under JDK 1.1.7B on Windows 95. It has
been tested successfully with the following systems:
| Windows:
Works successfully on:
|
| Macintosh:
Works successfully on:
|
| Solaris:
Works successfully on:
|
| Development Environments:
Works successfully on:
|
Printing was a new addition to Java beginning with JDK 1.1. TextPrinter
will not work with Java environments prior to JDK 1.1, and early releases
of JDK 1.1 were known to have certain problems. The JavaSoft site
contains numerous reports in its bug database documenting printing problems
on multiple platforms and printers under various releases of JDK 1.1 and
JDK 1.2. Developers may wish to keep an eye on the JavaSoft "Bug Parade"
database for printer bug status and workarounds.
Known Problems and Issues
Users should be aware of the following known problems and issues concerning Java printing using TextPrinter:
Printing from applications and applets
Printing is primarily a Java application technology. In particular, Java applet security restrictions disallow untrusted applet code from initiating a print job. As a result, TextPrinter will not generally work from untrusted applets, though different browsers and appletviewers may relax this condition.
Trusted (signed) applets are able to print using TextPrinter, though
in practice this depends on the specific browser or appletviewer.
There's a useful memo on how to create signed applets that can print available
at: http://www.adelaide.net.au/~bmodra/PrintJob.html.
Print dialog options
TextPrinter uses the JDK 1.1 printing architecture. JDK 1.1 is not able to print without having the user respond to a standard system print dialog (this restriction has being removed in JDK 1.2 and has been suggested for JDK 1.1).
Under Windows the following choices can be made by the user in the standard
print dialog and work correctly under TextPrinter:
a) Number of copies
b) Pages printed in reverse order
c) Pages printed collated
d) Print to file
e) Portrait vs landscape (except this feature had
a bug in Windows JDK 1.1.4 and earlier)
However, none of the above settings are reported as printer preferences in calls to toolkit.getPrintJob(), so they cannot be detected or controlled programmatically.
The "print page range" field in the standard Windows print dialog is
not supported by Java. TextPrinter includes a page range feature
to provide this capability.
Bugs in JDK 1.2 font system
The new Java2D font system is enabled for the first time in JDK 1.2 but causes two serious problems. First, the fonts are not "tuned", so the font quality is low. Second, due to a bug in the Java drawString method, in the JDK 1.2 beta releases Java printing drew a line from the upper left corner of the page to every printed character (see the Java "Bug Parade" database). In the final release of JDK 1.2, text printing using Java 2D was disabled entirely to prevent showing this problem. This problem still has not been fixed in JDK 1.2.1.
These problems are both avoided by reverting to the use of native (underlying
operating system) fonts when running your application, using a command
line option as follows:
java -Djava2d.font.usePlatformFont=true
YourApplication
This option is automatically used in the PrintTextFile 1.3 batch program
provided with this release. The use of this switch does not cause
problems when running under other JDK's. Once these problems are
fixed in JDK 1.2, you should be able to remove this command line option
and allow your TextPrinter-based programs to use the Java2D font system.
Problems with margins
Java printing has undergone many modifications and bug fixes from the early JDK 1.1.x release through the JDK 1.2 betas, particular on Windows. Many of these involved changes to page dimensions and resolution. Windows JDK 1.1.4 and earlier incorrectly reported resolution, resulting in a well-known "2/3 page problem" and small fonts. Sun's attempt to fix this in JDK 1.1.5 corrected the resolution but miscalculated page dimensions. JDK 1.1.6 was the same as JDK 1.1.5. JDK 1.2beta3 reverted to the same problem as JDK 1.1.4. Sun fixed these problems in JDK 1.1.7 and JDK 1.2, but also made the page dimensions correspond to the full physical page, instead of the printable area as before. Solaris has always reported page dimensions as the physical page (Unix is unable to detect the printable area), so now Windows and Solaris are the same. The Macintosh has always reported page dimensions as the printable area.
All these differences can be accommodated in TextPrinter by selecting
appropriate margins settings. Successive releases of TextPrinter have changes
to code and default margin settings tracking the latest JDK releases.
But this has made it difficult to write a single program that can print
correctly regardless of the underlying JDK and OS. To this end, the
sample application PrintTextFile1.3 provided with this release includes
the source code for a method
defaultMargin that can be used to
automatically configure TextPrinter 1.3 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. This code shows how a single program
can adjust its printed output for a broad range of Java platforms and OS's.
But given the many printers and printer drivers on different platforms,
you may find it useful to adjust the values inside the defaultMargin
method for your application and target system(s). Adding a fraction
of an inch to the margins may prove useful for certain printers, or, you
may find that for your printer(s) the margins can be reduced and you can
print even closer to the printable edge. You may wish to experiment
with TextPrinter margin settings to achieve optimal results for your system(s)
and printer(s).
Problems with Java FontMetrics
There are known problems in the Java FontMetrics class relative to printing.
Due to rounding in the individual character FontMetrics, the stringWidth
and charWidth methods supported by Java do not correspond exactly to what
drawString renders. The reported values may be either too big or
too small for different size fonts, but usually the cumulative effect is
too big, so that lines will wrap somewhat earlier than the rightmost printable
margin. However, printing and repositioning each word based on Java's
reported font metrics causes uneven spacing between words, and printing
and repositioning each character based on these metrics causes uneven spacing
within words. Neither of these workarounds was deemed acceptable
and so whole lines (or tab-separated sections of lines) are rendered by
TextPrinter at once. The result is optimal quality text printing
but lines that may be somewhat shorter on the page than they could be.
Please report any difficulties with Text Printer on your configurations
by email to products@wildcrest.com. Be sure to include what Java
release, OS, and printer you are using. Efforts will be made to fix
problems in Text Printer, but certain problems may not be possible for
it to detect and/or correct.